Answer to Question #292082 in C for Nickleodeon20

Question #292082

"Even" Now

by CodeChum Admin

I'm really fond of even numbers, you know? That's why I'll be letting you make another even number problem yet again. This time, you need to print from a range of two inputted numbers, n1 and n2 (inclusive), all the even numbers from n2 down to n1, in descending order.


Input


1. Value of n1


Description

The first integer of the range

Constraints

The value of n1 is guaranteed to be lesser than or equal to n2.

Sample

3
1
Expert's answer
2022-01-31T04:31:23-0500
#include <stdio.h>

int main() {
    int n1, n2;
    scanf("%d%d", &n1, &n2);

    n2 = n2 - n2 % 2; // if n2 was odd, then n2 % 2 == 1, and n2 - 1 is even
    for (int i = n2; i >= n1; i -= 2)
        printf("%d ", i);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS