Question: c++ For Loop: Output evens #include using namespace std; int main() { int n; int i; cout > n; cout /* Type your code here.
c++
For Loop: Output evens

#include
int main() { int n; int i;
cout > n;
cout
/* Type your code here. */
return 0; }
(1) Given positive integer n, write a for loop 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: 64 20 (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
Get step-by-step solutions from verified subject matter experts
