C Program to print all odd numbers up to the inputted number

Write a program in the c programming language to print all the odd numbers up to the inputted number.Make this program by using the for loop.  Below is the solution of the program-

/* Write a C Program to print all the odd numbers up to the inputted number*/

#include<stdio.h>
void main()
{
     int i,n;

     printf("Enter any number \n");
     scanf("%d",&n);

     printf("Odd numbers upto the inputted number are - \n");
     for(i=1;i<=n;i+=2)
     {
             printf(" %d \t",i);
     }
     getch();
}

There is also a second way to print the odd numbers up to the inputted number. You can also use the ‘if’ statement in the for loop to print the odd number. Below is the for loop section of the same C program of how you can use the ‘if’ statement –

for(i=1;i<=n;i++)
{
        if(i%2!=0)
        {
                printf("%d t",i);
        }
}

yashan has written 70 articles

2 thoughts on “C Program to print all odd numbers up to the inputted number

  1. Pingback: Kalpa Pharma
Cancel reply

Leave a Reply to Jagannath dad

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>