По разделам

 

Решение задачи Series 13


Дан набор ненулевых целых чисел; признак его завершения — число 0. Вывести сумму всех положительных четных чисел из данного набора. Если требуемые числа в наборе отсутствуют, то вывести 0.

Код (C/C++)

# include <iostream>
# include <windows.h>
# include <cmath>
# include <iomanip>
# include <fstream>
 
using namespace std;
 
int main ()
 
{
  SetConsoleCP(1251);
  SetConsoleOutputCP(1251);
 
  ifstream in ("Series13.txt");
  int a;
  int S = 0;
  cout << "Дан набор ненулевых чисел: " ;
  while (in >> a && a != 0) {
  	cout << a << " " ;
  	if (a > 0 && a%2 == 0) {
  		S += a;
  	}
  }
  cout << endl;
  if (S == 0) cout << 0;
  else   cout << "Cумма всех положительных четных чисел из данного набора = " << S << endl;   
  
  in.close ();
  
  system ("pause");
  return 0;
}

Код (Python)

import random

x = random.randrange(1,10)
print(x,end='; ')
k = 0
s = 0
if x > 0 and x % 2 == 0:
        s += x
while x != 0:
    x = random.randrange(-5,6)
    print(x,end='; ')
    if x > 0 and x % 2 == 0:
        s += x
    k += 1
    
print()
print("Amount:",k)
print("Sum of positive even numbers:",s)
									

Код (Pascal)

program Series13;
var
  i,R:Longint;
begin
R:=1;
i:=0;
  while(R<>0) do
   begin
     write('Введите число из набора: ');
     Readln(R);
     if (R>0) and odd(r)=False then i:=i+R;
   end;
  Writeln(i);
end.
									




Series. Абрамян
Series 1 Просмотров: 4391
Series 2 Просмотров: 2233
Series 3 Просмотров: 2007
Series 4 Просмотров: 2172
Series 5 Просмотров: 2051
Series 6 Просмотров: 2614
Series 7 Просмотров: 2893
Series 8 Просмотров: 3198
Series 9 Просмотров: 1865
Series 10 Просмотров: 2320
Series 11 Просмотров: 1750
Series 12 Просмотров: 2088
Series 13 Просмотров: 1519
Series 14 Просмотров: 1418
Series 15 Просмотров: 1702
Series 16 Просмотров: 2115
Series 17 Просмотров: 1916
Series 18 Просмотров: 2750
Series 19 Просмотров: 2443
Series 20 Просмотров: 1489
Series 21 Просмотров: 1681
Series 22 Просмотров: 1631
Series 23 Просмотров: 2018
Series 24 Просмотров: 1855
Series 25 Просмотров: 1423
Series 26 Просмотров: 1259
Series 27 Просмотров: 1199
Series 28 Просмотров: 1144
Series 29 Просмотров: 1164
Series 30 Просмотров: 1201
Series 31 Просмотров: 1158
Series 32 Просмотров: 1674
Series 33 Просмотров: 951
Series 34 Просмотров: 996
Series 35 Просмотров: 1379
Series 36 Просмотров: 1486
Series 37 Просмотров: 920
Series 38 Просмотров: 1237
Series 39 Просмотров: 877
Series 40 Просмотров: 1214

Комментарии

Чтобы написать комментарии вам нужно войти в систему или зарегистрироваться



Заявка на расчет