Series 4. Дано целое число N и набор из N вещественных чисел. Вывести сумму и произведение чисел из данного набора.
Решение на Python 3
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)
Решение на 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;
}