Вопрос задан 14.09.2018 в 17:17. Предмет Информатика. Спрашивает Никифорова Анюта.

ПОМОГИТЕ! Изменить данную программу для while и repeat program_n1; var i,s:integer; begin s:=0;for

i=10 to 99 do s:=s+i; writeln ('Сумма=',s); end.
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Лозейко Саша.
While:
program n2;
var i,s:integer;
begin
s:=0;
i:=10;
while i<100 do
 begin
 s:=s+i;
 i:=i+1;
 end;
writeln ('Сумма=',s);
end.

repeat:
program n3;
var i,s:integer;
begin
s:=0;
i:=10;
repeat
 s:=s+i;
 i:=i+1;
until i=100;
writeln ('Сумма=',s);
end.

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

Changing the Program to Use a While or Repeat Loop

To modify the given program to use a `while` or `repeat` loop instead of a `for` loop, we need to rewrite the loop structure. Here's an example of how you can change the program:

```pascal program program_n1; var i, s: integer; begin s := 0; i := 10; // Set the initial value of i

while i <= 99 do // Use a while loop with a condition begin s := s + i; i := i + 1; // Increment i end;

writeln('Сумма=', s); end. ```

In this modified program, we initialize `i` with the value 10 before the loop. Then, we use a `while` loop with the condition `i <= 99` to iterate through the numbers from 10 to 99. Inside the loop, we add the current value of `i` to `s` and increment `i` by 1. Finally, we print the value of `s` using the `writeln` statement.

This modified program will produce the same result as the original program, but it uses a `while` loop instead of a `for` loop.

Please note that the modified program assumes you are using the Pascal programming language. If you are using a different programming language, the syntax may vary.

0 0

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

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

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