Answer to Question #238257 in C++ for Haya

Question #238257

Suppose that the input is 10 -6 12 -5 -4 0. What is the output of the following code?



int num;

int sum = 0;

cin >> num;

while (num != 0)

{

if (num>0)

sum = sum + num;

else

sum = sum - num;

cin >> num;

}

cout << ” Sum = ” << sum << endl;


1
Expert's answer
2021-09-16T15:36:39-0400
#include<iostream>
using namespace std;
int main(){
	int num;


int sum = 0;


cin >> num;


while (num != 0)


{


if (num>0)


sum = sum + num;


else


sum = sum - num;


cin >> num;


}


cout << "Sum =  "  << sum << endl;
}

For input is: 10 -6 12 -5 -4 0,
Output is: 37

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS