Вопрос задан 03.05.2019 в 21:10. Предмет Информатика. Спрашивает Абдрахманова Рената.

Написать программу в паскале.Дано натуральное число n (n<1000)Определить:а) сколько цифр в

числеб) чему равна сумма его цифр
0 0
Перейти к ответам

Ответы на вопрос

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Цокало Рома.
Program znanijacom;
uses crt;
var
n:string;
i,k,r,c,b:integer;
num:array [1..4] of char;
begin
writeln('vvedite celoe chislo <1000:');
read(n);

k:=length(n);
writeln('Cufr v chisle: ',k);

for i:=1 to k do
begin

num[i]:=n[i];
val(num[i],c,b);
r:=r+c;
end;
writeln('Ux cymma : ',r);
end.

0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Program in Pascal to Determine the Number of Digits and the Sum of Digits of a Natural Number

Sure, I can help you with that! Below is a simple program in Pascal that takes a natural number 'n' as input and determines: a) How many digits are in the number b) What is the sum of its digits

```pascal program NumberProperties;

var n, num, digit, digitCount, sum: integer;

begin // Input a natural number write('Enter a natural number (n < 1000): '); readln(n); // Initialize variables num := n; digitCount := 0; sum := 0; // Calculate the number of digits and the sum of digits while num > 0 do begin digit := num mod 10; // Extract the last digit digitCount := digitCount + 1; // Increment the digit count sum := sum + digit; // Add the digit to the sum num := num div 10; // Remove the last digit end; // Output the results writeln('The number of digits in ', n, ' is ', digitCount); writeln('The sum of its digits is ', sum); end. ```

To run this program, you can use a Pascal compiler such as Free Pascal (FPC) or Turbo Pascal. After running the program, it will prompt you to enter a natural number less than 1000. Once you input the number, the program will calculate and display the number of digits in the number and the sum of its digits.

Feel free to try it out and let me know if you have any questions or need further assistance!

0 0

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос