Given a list of numbers, stop processing input after the cumulative sum of all the input becomes negative.logic in c??
Answers
Answer: as explained
Explanation:
In this we will be using a while loop and keep on checking if the value of sum is still greater than zero. That is the checking will be done by the entry condition as it is an entry control loop if the condition it true loop condition will be executed via the iteration.
void main ()
{
int sum=0, n;
while (sum>0)
{
cout<<"enter the value ";
cin>>n;
sum=+n;
}
cout<<" the cumulative value is negative";
}
In this loop body iteration continues and sum value keeps on getting updated. As soon as the condition gets false as we enter a number which is given as input is greater than the sum then we have the situation as negative cumulative value. Thus the loop execution stops and control comes out of the loop and prints the resultant as negative value involved.