Rosa
4 год назад
С клавиатуры вводятся K чисел. Подсчитать количество отрицательных чисел и произведение нечетных. Используемый цикл While.
ОТВЕТЫ
Дмитрий
Oct 24, 2020
#include <iostream>
using namespace std;
int main(int argc, char *argv[]){ int array[100]; int i = 0; // счетчик цикла int K; int otr = 0; int nech = 1; cout << "Input K: "; cin >> K; cout << endl; cout << "Input numbers: " << endl; while(i != K) { cin >> array[i]; i++; } i = 0; while(i != K) { if(array[i] < 0) { otr++; } if((array[i] % 2) != 0) { nech *= array[i]; } i++; } cout << "Otr = " << otr << endl << "Proizv. nechet = " << nech << endl; return 0;}
using namespace std;
int main(int argc, char *argv[]){ int array[100]; int i = 0; // счетчик цикла int K; int otr = 0; int nech = 1; cout << "Input K: "; cin >> K; cout << endl; cout << "Input numbers: " << endl; while(i != K) { cin >> array[i]; i++; } i = 0; while(i != K) { if(array[i] < 0) { otr++; } if((array[i] % 2) != 0) { nech *= array[i]; } i++; } cout << "Otr = " << otr << endl << "Proizv. nechet = " << nech << endl; return 0;}
393
Смежные вопросы: