Имеется последовательность чисел a1, a2 , ..., aN . Найти сумму первых из них, произведение которых не превышает заданного числа М.СИ++. #include #include #include
int main() { int N, M; cout << "Enter the number of elements in the sequence: "; cin >> N;
int sequence[N]; cout << "Enter the elements of the sequence: "; for (int i = 0; i < N; i++) { cin >> sequence[i]; } cout << "Enter the maximum product value M: "; cin >> M; int sum = 0; int product = 1; for (int i = 0; i < N; i++) { if (product * sequence[i] <= M) { product *= sequence[i]; sum += sequence[i]; } else { break; } } cout << "The sum of the first elements whose product does not exceed " << M << " is: " << sum << endl; return 0;
using namespace std;
int main() {
int sequence[N];int N, M;
cout << "Enter the number of elements in the sequence: ";
cin >> N;
cout << "Enter the elements of the sequence: ";
for (int i = 0; i < N; i++) {
cin >> sequence[i];
}
cout << "Enter the maximum product value M: ";
cin >> M;
int sum = 0;
int product = 1;
for (int i = 0; i < N; i++) {
if (product * sequence[i] <= M) {
product *= sequence[i];
sum += sequence[i];
} else {
break;
}
}
cout << "The sum of the first elements whose product does not exceed " << M << " is: " << sum << endl;
return 0;
}