how to proceed in this question i dont able to find the approach to proceed pls suggest me to proceed
Simple input problem approach
hi @dipeshgupta197
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:
- Put a loop till the END OF INPUT.
- Add the new number to the previous sum.
- If the sum is positive print the current number.
- 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;
}
doubt is resolved now
HI @dipeshgupta197 Hope your doubt has been resolved… for now I closing this doubt if you still have any isuue please do contact
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.