
ПОМОГИТЕ! Изменить данную программу для while и repeat program_n1; var i,s:integer; begin s:=0;for
i=10 to 99 do s:=s+i; writeln ('Сумма=',s); end.

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

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



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.


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







Последние заданные вопросы в категории Информатика
-
Математика
-
Литература
-
Алгебра
-
Русский язык
-
Геометрия
-
Английский язык
-
Химия
-
Физика
-
Биология
-
Другие предметы
-
История
-
Обществознание
-
Окружающий мир
-
География
-
Українська мова
-
Информатика
-
Українська література
-
Қазақ тiлi
-
Экономика
-
Музыка
-
Право
-
Беларуская мова
-
Французский язык
-
Немецкий язык
-
МХК
-
ОБЖ
-
Психология
-
Физкультура и спорт
-
Астрономия
-
Кыргыз тили
-
Оʻzbek tili