Предмет: Информатика, автор: Smotrovchanin

Помогите, пожалуйста, в паскале написать программу:)
Найти сумму чётных чисел от 2 до 21
Нужно три способа
Зарание спасибо:)


Smotrovchanin: Хотя бы пару способов напишите, пожалуйста
shayger: Нужны способы именно написания программы, или конкретно нахождения суммы?
Smotrovchanin: @Shayger нужна программа, которая будет считать это
Smotrovchanin: Shayger нужна программа, которая будет считать это
shayger: Подожди немного, сейчас напишу.

Ответы

Автор ответа: shayger
0
1 способ
type
   massiv = array [2..21] of integer;
var
    mass : massiv;
    i, summa : integer;
 
begin
   summa := 0;
   for i:=2 to 21 do
        begin
           mass[i]:=i;
           if (mass[i] mod 2 = 0) then
              summa := summa + mass[i]
        end;
   writeln('Сумма четных эл-тов равна : ', summa);
   readln;
end.
2 Способ
program z;
var
        a : array[2..21] of integer;
        i,summ : integer;
        b : array[2..21] of integer;


begin
        for i:= 2 to 21 do
        begin
         a[i]:=i;
        end;

        for i:=2 to 21 do
          begin
          if a[i] mod 2 = 0 then
                begin
                  b[i]:=a[i];
                end;

          end;

        summ:=0;
        for i:=2 to 21 do
        begin
         summ:=summ+b[i];
        end;
        Writeln(summ);
        readln;

end.


Похожие вопросы
Предмет: Русский язык, автор: jonbraims
Предмет: Английский язык, автор: лучшая2006
Read the text about healthy and unhealthy food.

In our modern world it is popular to keep a healthy lifestyle. It includes not only some physical exercises, going to the gym, but also eating healthy food.

As you know, some people try to choose healthy food, but it is very difficult for them to eat only healthy food. It takes a lot of time to cook it. Modern people are very busy. Sometimes healthy food is more expensive than unhealthy food. But experts say that we can cook healthy dishes very quickly. For example, a healthy burger. You need only vegetables, wholemeal bread and chicken.
In the morning you can eat cereal with milk or yoghurt. It does not take a lot of time to cook these dishes. For lunch, you can eat soup and a salad. In the evening you do not need much time to cook rice and cut some vegetables. The most important thing is that you should not skip meals and have only snacks.

As for unhealthy food, it is cheaper and faster. You do not spend much time on cooking. But the most dangerous for health is junk food or food containing empty calories. It is food with low biological value and high content of solid fats, calories and sugar. This category includes fizzy drinks (Cola, Pepsi), sweets, chips, chocolate bars and other snacks. This type of food influences our health. It does not give any vitamins and minerals, only empty calories and harmful additives. People can have a stomachache, some problems with their skin, teeth and hair, if they eat junk food very often.

So, if you go to a shop to buy some food, think about your health. Try to choose something tasty and healthy.

Write "true" or "false":

1. Experts say that people can cook healthy dishes quickly.



2. It does not take a lot of time to cook healthy dishes.



3. Junk food includes peas, rice, lettuce and others.