how can we first take 5 number from user and then print numbers till which sum was positive … i wish to first take all five inputs …
Doubt regarding question
hi @hridyansh28_cff82018adc2f216
#include<iostream>
using namespace std;
int main(){
int i,no,sum=0;
for(i=1;;i++){
cin>>no;
sum=sum+no; // add to sum
if(sum>=0){ // print no if sum >= 0
cout<<no<<endl;}
else{
break; // otherwise break
}
}
return 0;
}
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.