Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Step 1: Copy this program into your C++program editor, and compile it. Hopefully you will not get any error messages. Step 2: Run your program
Step 1: Copy this program into your C++program editor, and compile it. Hopefully you will not get any error messages. Step 2: Run your program type in "5" to see what it prints. Notice that all of the output is on one line this time because we used spaces between the numbers, and the endl is printed after the for loop. The variable "num" declared in the for loop is only valid inside the loop itself. If we tried to print it out after the loop we would get a compiler error saying the variable is "out of scope". Step 3: Edit the program and add a second for loop to print out the EVEN numbers [0..input-1] on a single line. To do this, you need to modify the initialization, the logical expression, and the update variables code. You can use the same "cout" code as the first for loop. Step 4: Compile and test your program with a variety of input values. For example, if the user types in an 11, you should see: Enter a number: 11 10223446586107891011 Step 5: Edit your program again and add a third for loop to print the ODD numbers [input..1] on a single line. This problem is tricky because we are decreasing the numbers as we are printing, and we have to figure out the first value to print. If input is odd, we start by printing input. If input is even, we must start by printing input- 1. Step 6: Compile and test your program with a variety of input values. For example, if the user types in an 8 , you should see: Enter a number: 8 12345678 0246 7531 Step 7: Once you think your program is working correctly, upload your final program into the auto grader by following the instructions below
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started