Вводится последовательность чисел, 0 – конец последовательности. Найти сумму и произведение чисел, принадлежащих отрезку [-4;8]. С использованием while.Заранее спасибо Thread restrictions: The topic author allowed to post messages in the topic only to the following groups (and higher ranked): Staff Members and Curators
#include <iostream> using namespace std; int main() { int a; int sum = 0; int prod = 1; while(1){ cin>>a; if(a == 0) break; if(a >= -4 && a <= 8){ sum+=a; prod*=a; } } cout<<"Sum: "<<sum<<endl; cout<<"Product: "<<prod<<endl; return 0; } C #include <iostream> using namespace std; int main() { int a; int sum = 0; int prod = 1; while(1){ cin>>a; if(a == 0) break; if(a >= -4 && a <= 8){ sum+=a; prod*=a; } } cout<<"Sum: "<<sum<<endl; cout<<"Product: "<<prod<<endl; return 0; }