Question: 1 7 . 2 2 PRACTICE: Loops ( for ) * : Output evens ( 1 ) Given positive integer n , write a for

17.22 PRACTICE: Loops (for)*: Output evens
(1) Given positive integer n, write a for loop in c ++that outputs the even numbers from n down to 0. If n is odd, start with the next lower even number. Hint: Use an if statement and the % operator to detect if n is odd, decrementing n if so.
Enter an integer:
7
Sequence: 6420
(2) If n is negative, output 0. Hint: Use an if statement to check if n is negative. If so, just set n =0.
Enter an integer:
-1
Sequence: 0

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 Programming Questions!