Question: Write a program that reads a set of integers until a zero is entered. Excluding zero, the program should print a count of and a

Write a program that reads a set of integers until a zero is entered. Excluding zero, the program should print a count of and a sum of:

positive numbers

negative numbers

even numbers

odd numbers

positive even numbers

negative odd numbers.

all numbers

Use debug statements to show cumulative sums as each new number is read and processed.

Implement this program incrementally; i.e. first build the loop and test for only one set of conditions (e.g. even and odd). Get that program to work, and then add features to it a little at a time, testing as you go along. If you use "yank and put" in vi (copy and paste) and then modify the copy, you can save yourself alot of typing, since the different sections of this program are very similar to each other.

Use #ifdef DEBUG conditional compilation around your debug statements to turn on and off debugging. Turn debugging off when you turn in your program. You can write this program with just a single function, main(). Put the code in a file called numbers.c. A sample output from my program looks like:

 15 debug:15 is positive(count = 1, total = 15) debug:15 is odd(count = 1, total = 15) debug:Total(count = 1, total = 15) 2 debug:2 is positive(count = 2, total = 17) debug:2 is even(count = 1, total = 2) debug:2 is positive and even(count = 1, total = 2) debug:Total(count = 2, total = 17) -3 debug:-3 is negative(count = 1, total = -3) debug:-3 is odd(count = 2, total = 12) debug:-3 is negative and odd(count = 1, total = -3) debug:Total(count = 3, total = 14) -8 debug:-8 is negative(count = 2, total = -11) debug:-8 is even(count = 2, total = -6) debug:Total(count = 4, total = 6) 0 There were 2 positive numbers totaling 17 There were 2 negative numbers totaling -11 There were 2 even numbers totaling -6 There were 2 odd numbers totaling 12 There were 1 positive even numbers totaling 2 There were 1 negative odd numbers totaling -3 There were 4 total numbers totaling 6 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!