По разделам

 

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


Дано целое число N и набор из N вещественных чисел. Вывести
сумму и произведение чисел из данного набора.

Код (C/C++)

#include <bits/stdc++.h>
using namespace std;

int main() {
	srand((int)time(0));
	int N = rand() % 10 + 1;
	cout << "N = " << N << endl;
	
	double s = 0.0, p = 1.0;
	float x;
	for(int i = 0; i < N; i++) {
		x = rand() % 10 + 1;
		cout << x << " ";
		//cin >> x;
		s += x;
		p *= x;
	}
	
	cout << endl;
	cout << "Sum = " << s << endl;
	cout << "Product = " << p << endl;

	return 0;
}

Код (Python)

import random

N = 5
s = 0
p = 1
for i in range(N):
    x = random.randrange(1,6)
    #x = random.uniform(1, 10)
    print(x, end="; ")
    s += x
    p *= x
print()
print('Sum = ', s)
print('Product = ', p)
									

Код (Pascal)

program Series4;
var
  R,Sum,Pro:Real;
  i,N:Integer;
begin
  Sum:=0;
  Pro:=1;
  Write('Введите N: ');
  Readln(N);
  for i:=1 to N do
   begin
     Write('Введите ',i,' число: ');
     Readln(R);
     Sum:=Sum+R;
     Pro:=Pro*R;
   end;
  Writeln(Sum,' ',Pro);
end.
									




Series. Абрамян
Series 1 Просмотров: 4443
Series 2 Просмотров: 2268
Series 3 Просмотров: 2035
Series 4 Просмотров: 2217
Series 5 Просмотров: 2092
Series 6 Просмотров: 2674
Series 7 Просмотров: 2934
Series 8 Просмотров: 3228
Series 9 Просмотров: 1914
Series 10 Просмотров: 2365
Series 11 Просмотров: 1775
Series 12 Просмотров: 2131
Series 13 Просмотров: 1557
Series 14 Просмотров: 1447
Series 15 Просмотров: 1734
Series 16 Просмотров: 2146
Series 17 Просмотров: 1956
Series 18 Просмотров: 2784
Series 19 Просмотров: 2489
Series 20 Просмотров: 1541
Series 21 Просмотров: 1711
Series 22 Просмотров: 1655
Series 23 Просмотров: 2055
Series 24 Просмотров: 1887
Series 25 Просмотров: 1454
Series 26 Просмотров: 1290
Series 27 Просмотров: 1223
Series 28 Просмотров: 1171
Series 29 Просмотров: 1192
Series 30 Просмотров: 1231
Series 31 Просмотров: 1185
Series 32 Просмотров: 1704
Series 33 Просмотров: 979
Series 34 Просмотров: 1027
Series 35 Просмотров: 1406
Series 36 Просмотров: 1516
Series 37 Просмотров: 948
Series 38 Просмотров: 1268
Series 39 Просмотров: 897
Series 40 Просмотров: 1243

Комментарии

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



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