Tuesday, July 3, 2012

Sums until a negative value

Assalamu Alaikum. Hope you all are well by the grace of Almighty ALLAH. Today we learn how to find out the sum of input numbers until a negative number. Take a look at the problem.

Problem: Write a program segment that reads and sums data until  a negative value is read.

Sample Input:

1
2
3
4
5
-2

Sample Output:

15

Solution:




We can also do this program by the following way.


We can do this program by do while loop. Take a look at the program..


We can also do this program by the following way..


Thank you all..:)




0 comments:

Post a Comment