C Program to Display Odd Numbers Between 1 to 100 using For and While Loop

In this C program, we will learn to print all odd numbers between 1 to N using while loop and for loop.

Required Knowledge


C program to print odd numbers between 1 to 100 using for loop

#include <stdio.h>  
  
int main() {  
    int counter; 
    printf("Odd numbers between 1 to 100\n");  
   
    for(counter = 1; counter <= 100; counter++) {    
        if(counter%2 == 1) { 
            /* counter is odd, print it */
            printf("%d ", counter);  
        }  
    }  
  
    return 0;  
} 

Output
Odd numbers between 1 to 100
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 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99

C program to print odd numbers from 1 to N using while loop

#include <stdio.h>  
  
int main() {  
    int counter; 
    printf("Odd numbers between 1 to 100\n");  
  
    counter = 1;
    while (counter <= 100) {  
        printf("%d ", counter);
        /* Add 2 to current odd number 
          to get next odd number */
        counter = counter + 2;  
    }  
    return 0;  
} 

Output
Odd numbers between 1 to 100
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 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99

Related Topics
C program to print natural numbers in reverse order from N to 1
C program to print even numbers between 1 to N using for and while loop
C program to find sum of all even numbers between 1 to N using for loop
C program to find sum of all odd numbers between 1 to N using for loop
C program to print all prime numbers between 1 to N using for loop
C program to check a number is odd or even using conditional operator
C program to find perfect numbers between 1 to N using for loop
C program to check whether a number is odd or even using switch statement
C program to print multiplication table of a number
List of all C programs