Not able to figure out the answer

Hi im not able to figure out the answer could i get some help

You may be Wondering where is the N(No of inputs specified)?

Till when we need to take input??

Ans to the question is present in the question itself, as it said print the numbers till u get positive cumulative sum, so u need to take input till u got the positive cumulative irrespective of the number inputs.

Algo:

  1. Put a loop till the END OF INPUT.
  2. Add the new number to the previous sum.
  3. If the sum is positive print the current number.
  4. Otherwise, break the loop.

refer this code–>

#include <bits/stdc++.h>
using namespace std;

int main() {
    int sum=0;
    int n;

    while(1){
        cin >> n;
        sum += n;
        if(sum<0)
            break;
        cout << n << '\n';
    }

    return 0;
}

hey, if still there is anything do let me know…

1 Like

thanks u caught the point right and knew the problem TYSM

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.