Answer to Question #346036 in C for Chariz

Question #346036

Instructions:



Using the do…while() loop, continuously scan for integers, but add up only all the positive integers and store the total in one variable.


The loop shall only be terminated when the inputted integer is zero. Afterwards, print out the total of all inputted positive integers.


Input



1. A series of integers



Output



The first multiple lines will contain message prompts to input the integers.


The last line contains the total of all positive integers inputted.



Enter·n:·2


Enter·n:·3


Enter·n:·4


Enter·n:·-1


Enter·n:·-5


Enter·n:·1


Enter·n:·0


Total·of·all·positives·=·10

1
Expert's answer
2022-05-30T15:14:18-0400
#include <stdio.h>
int main()
{
	int number;
	int result = 0;
	do
	{
		printf("Enter n: ");
		scanf_s("%d", &number);
		if (number > 0)
			result = result + number;
	} while (number != 0);
	printf("Total of all positives = %d", result);
	return 0;
}

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
APPROVED BY CLIENTS