Вопрос задан 05.05.2019 в 02:48. Предмет Информатика. Спрашивает Байгушова Дарья.

Вычислите сумму: 1+1/2+1/3+1/4+…+1/10. Решите задачу в 2 вариантах - с использованием операторов

while и repeat.
0 0
Перейти к ответам

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

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Крюков Денис.
Var
i:integer;
s:real;
begin
i:=1; s:=1;
while i<>10 do
begin
i:=i+1;
s:=s+1/i;
end;
writeln('Вычисленно с помощью цикла while: ',s);
i:=1; s:=1;
repeat
i:=i+1;
s:=s+1/i;
until i=10;
writeln('Вычисленно с помощью цикла repeat: ',s)
end.

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

Calculating the Sum of a Series

To calculate the sum of the series 1 + 1/2 + 1/3 + 1/4 + … + 1/10, we can use two different approaches: one using the `while` operator and the other using the `repeat` operator.

Using the `while` Operator

To calculate the sum using the `while` operator, we can iterate through the series and accumulate the sum.

```lua -- Using the while operator local i = 1 local sum = 0 while i <= 10 do sum = sum + 1/i i = i + 1 end print("The sum of the series using while operator is: " .. sum) ``` [[SOURCE #4]]

Using the `repeat` Operator

Alternatively, we can calculate the sum using the `repeat` operator.

```lua -- Using the repeat operator local j = 1 local total = 0 repeat total = total + 1/j j = j + 1 until j > 10 print("The sum of the series using repeat operator is: " .. total) ``` [[SOURCE #9]]

By using either the `while` or `repeat` operator, we can calculate the sum of the given series.

0 0

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

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

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