integer valuein is read from input. write a while loop that sums all integers read from input until a positive integer is read. the positive integer should not be included in the sum. ex: if the input is -43 -46 -18 -11 27, then the output is:



Answer :

To write a while loop that sums all integers read from input until a positive integer is read and the positive integer should not be included in the sum, check the code given below.

What is while loop?

A while loop is a control flow statement that enables code to be executed repeatedly based on a specified Boolean condition in the majority of computer programming languages. The while loop can be viewed as an iterative version of the if statement.

//CODE//

#include <iostream>

using namespace std;

int main()

{

int sum=0;

int a[5]={-39,-13,-49,-11,48};

int i=0;

while(a[i]<0&&i<5)

{

if(a[i]>0)

{

break;

}

else

{

sum = sum+ a[i];

i++;

}

}

printf("%d",sum);

}

Learn more about while loop

https://brainly.com/question/19344465

#SPJ4

Other Questions