Odd numbers from 1 to N

C program to print ODD numbers from 1 to N.


Program

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

    printf("Enter the value of N\t:");
    scanf("%d",&n);

    printf("Odd number from 1 to %d are\n",n);
    for(i=1;i<=n;i++)
    {
        if(i % 2 != 0)
        {
            printf("%d ",i);
        }
    }

    getch();
}

Output

Enter the value of N    :45
Odd number from 1 to 45 are
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45

Program

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

    printf("Enter the value of N\t:");
    scanf("%d",&n);

    printf("Odd number from 1 to %d are\n",n);
    for(i=1;i<=n;i=i+2)
    {
        printf("%d ",i);
    }

    getch();
}

Output

Enter the value of N    :45
Odd number from 1 to 45 are
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45