Algorithm Analysis
We will use a for
loop. We will iterate over all numbers from to in ascending order and print the odd ones.
Algorithm Implementation
Read the input data.
scanf("%d %d", &a, &b);
Iterate over numbers from to in ascending order and print the odd ones.
for (i = a; i <= b; i++) if (i % 2 == 1) 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 = a; i <= b; i++) if (i % 2 == 1) System.out.print(i + " "); con.close(); } }
Python Implementation
Read the input data.
a, b = map(int, input().split())
Iterate over numbers from to in ascending order and print the odd ones.
for i in range(a, b + 1): if i % 2 == 1: print(i, end=" ")