Вопрос задан 23.11.2023 в 17:38. Предмет Информатика. Спрашивает Сарибекян Нарек.

Прошу, допоможіть, будь ласка! Даю 40 баллів! Виконати у середовищі Pascal. 1. Скласти програму

яка з чисел від 10 до 100 виводить на екран ті, що діляться на 5. 2. Скласти програму яка для кожного числа від 20 до 99 друкує на екрані суму його цифр.​
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Юдина Карина.

Відповідь:

Виведення чисел від 10 до 100, що діляться на 5:

program div5;

var i: integer;

begin

 for i := 10 to 100 do

 begin

   if (i mod 5 = 0) then

     writeln(i);

 end;

end.

Виведення суми цифр для кожного числа від 20 до 99:

program digitsum;

var i, sum, ones, tens: integer;

begin

 for i := 20 to 99 do

 begin

   ones := i mod 10;

   tens := i div 10;

   sum := ones + tens;

   writeln(i, ' : ', sum);

 end;

end.

У цій програмі ми використовуємо операції ділення і взяття остачі від ділення, щоб отримати розряди десятків і одиниць для кожного числа. Потім ми додаємо ці розряди, щоб отримати суму цифр.

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

Program 1: Divisible by 5

To write a program in Pascal that prints the numbers from 10 to 100 that are divisible by 5, you can use a loop to iterate through the numbers and check if each number is divisible by 5. Here's an example program:

```pascal program DivisibleBy5;

var num: integer;

begin for num := 10 to 100 do begin if num mod 5 = 0 then writeln(num); end; end. ```

In this program, we declare a variable `num` of type `integer` to represent the numbers from 10 to 100. We then use a `for` loop to iterate through the numbers from 10 to 100. Inside the loop, we use the `mod` operator to check if the current number is divisible by 5 (`num mod 5 = 0`). If it is, we use the `writeln` procedure to print the number to the screen.

Program 2: Sum of Digits

To write a program in Pascal that prints the sum of the digits for each number from 20 to 99, you can use a loop to iterate through the numbers and calculate the sum of their digits. Here's an example program:

```pascal program SumOfDigits;

var num, digit, sum: integer;

begin for num := 20 to 99 do begin sum := 0; // Extract each digit and add it to the sum digit := num; while digit > 0 do begin sum := sum + (digit mod 10); digit := digit div 10; end; writeln('Number:', num, ' Sum of Digits:', sum); end; end. ```

In this program, we declare three variables: `num` to represent the numbers from 20 to 99, `digit` to store each digit of the number, and `sum` to store the sum of the digits. We use a `for` loop to iterate through the numbers from 20 to 99. Inside the loop, we initialize the `sum` variable to 0 and then use a `while` loop to extract each digit from the number and add it to the sum. Finally, we use the `writeln` procedure to print the number and its corresponding sum of digits to the screen.

Please note that the above programs are written in Pascal and should be executed in a Pascal compiler or IDE.

0 0

Похожие вопросы

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

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

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