Science, asked by prakashrupantaran, 1 month ago

write an algorithm to find sum of any five non negative numbers.

Answers

Answered by sreekuttan68
3

Answer:

Explanation:

1. Declare the variables cnt and sum as 0.

2. start a for loop. Initializing x as 1, x should be less than or equal to 1 and the update statement should x++

3. Ask the user to enter the values (declare the scanner class stuff outside the loop) lets say the user enters the values in a variable called num.

4. inside the loop write an if statement which checks if the number entered by the user is positive or negative. if(num>=0)

5. inside the if construct put the statement cnt++ and sum+=num

6. Exit the loop and display the output.

From this you will get the sum of all the positive numbers and their count.

Similar questions