Odd number
Opposite of even numbers, odd numbers are having a difference of 3 unit or number. In other words, if the number is not completely divisible by 2 then it is an odd number.
Logic
The logic for printing odd numbers are pretty simple and straight forward, we only need to check if the number is not divisible by 2. If the number is not divisible by 2, then we have to print it.
Program
#include <stdio.h> int main() { int i, n; // Take input from user. printf("Print all odd numbers till : "); scanf("%d", &n); printf("\nOdd numbers from 1 to %d are : \n", n); for(i = 1; i <= n; i++) { // Check for odd or not. if((i % 2) != 0) { printf("%d ", i); } } return 0; }
Output
Print all odd numbers till : 50
Odd numbers from 1 to 50 are :
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49