Загрузка...

Help, I'm stupid. Task in c++

Thread in C/C++ created by Envil Nov 27, 2022. 282 views

  1. Envil
    Envil Topic starter Nov 27, 2022 https://zelenka.guru/threads/5425786/ -изи 500р 97 Sep 1, 2019
    Вводится последовательность чисел, 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
     
  2. xtrunov
    или попробуй
     
    1. Envil Topic starter
    2. xtrunov
  3. LVV
    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;
    }
     
    1. Envil Topic starter
    2. LVV
      Envil, закрой тему
Top
Loading...