Series 6. Дано целое число N и набор из N положительных вещественных чисел. Вывести в том же порядке дробные части всех чисел из данного набора (как вещественные числа с нулевой целой частью), а также произведение всех дробных частей.
Решение на Python 3
import random
N = random.randrange(1,10)
print("N = ",N)
p = 1
for i in range(N):
#x = random.randrange(1,6)
x = random.uniform(0, 10)
y = x - int(x)
p *= y
print(y," : ",x," : ",p)
print()
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 p = 1.0;
float x;
double fractpart, intpart;
for(int i = 0; i < N; i++) {
x = (rand() % 1000) / 100.0;
//cin >> x;
fractpart = modf(x, &intpart);
p *= fractpart;
cout << x << " : " << fractpart;
cout << " : " << p << endl;
}
cout << endl;
cout << "Product = " << p << endl;
return 0;
}