C Program to print odd numbers till N: To print the odd numbers till N.
Odd Number: Any number which is divided by two and gives the remainder as 1 then that Number is referred to an odd number such as 1, 3, 5, 7, ….

Algorithm to print odd numbers

  1. Take input. N
  2. Traverse from 0 to N
  3. Calculate rem = i % 2
    If rem == 1
    Print odd Number
    else
    Continue

C Program to print odd numbers till N

#include<stdio.h>
void main()
{
int no , i ;
printf("Enter a Number\n");
scanf("%d", &no); // take input from user the n
printf( "\nodd numbers till %d:\n",no);
// Iterate till no
for(i=0;i<=no;i++)
{
//Condition to check odd number
if(i % 2 == 1)
printf("%d\n",i); //print odd number
else
continue; // otherwise skip
}
printf("\n");
}

Output :

C Program to print odd numbers till N

Write A Comment