Even numbers from 1 to N

C program to print EVEN 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("Even 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    :56
Even number from 1 to 56 are
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56

Program

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

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

    printf("Even number from 1 to %d are\n",n);

    for(i=2;i<=n;i=i+2)
    {
        printf("%d ",i);
    }
    getch();
}

Output

Enter the value of N    :56
Even number from 1 to 56 are
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56