Friday, July 6, 2012

Count odd & even until a negative value

Assalamu Alaikum. Hope you all are well by the grace of Almighty ALLAH. Today we learn how to count odd and even numbers until a negative input. Take a look at the problem.

Problem 1: Ten numbers are entered from the keyboard. Write a program to find out how many of them are even and how many are odd.

Sample input:    0 1 2 3 5 9 -4 -6 0 10
Sample output: Even: 2, Odd: 4

Solution:




Problem 2: Write a program segment that reads positive integer values and count the number of even and odd numbers, until a negative value is read.

Solution: 


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


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


Thank you all..:)



0 comments:

Post a Comment