Algorithm Analysis
Let's use a for
loop. We'll iterate through all the numbers from to in descending order and print the even ones.
Algorithm Implementation
Read the input data.
scanf("%d %d", &a, &b);
Iterate through the numbers from to in descending order and print the even ones.
for (i = b; i >= a; i--) if (i % 2 == 0) printf("%d ", i);
Java Implementation
import java.util.*; class Main { public static void main(String[] args) { Scanner con = new Scanner(System.in); int a = con.nextInt(); int b = con.nextInt(); for(int i = b; i >= a; i--) if (i % 2 == 0) System.out.print(i + " "); con.close(); } }
Python Implementation
Read the input data.
a, b = map(int, input().split())
Iterate through the numbers from to in descending order and print the even ones.
for i in range(b, a - 1, -1): if i % 2 == 0: print(i, end=" ")