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
#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);
}
Comments
Leave a comment