Write a C Program to print all even numbers up to inputted number

Write a program in the c programming language to print all the even numbers up to the inputted number by using the for loop statement. Below is the solution of the C program –

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

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

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

     printf("even numbers up to inputted number are - \n");
     for(i=2;i<=n;i+=2)
     {
             printf(" %d \t",i);
     }
     getch();
     }

Input- Enter any number – 20

Output- Even numbers up to inputted number are  –  2  4  6  8  10  12  14  16  18  20


There is also a second method to make this same program. You can also use ‘ if ‘ statement in the for loop section of the program to print the even numbers. Below is the for loop section of the same C program –

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

yashan has written 70 articles

7 thoughts on “Write a C Program to print all even numbers up to inputted number

  1. #include
    #include

    int main() {

    int num1,num2,i;

    printf(“Enter the Starting number : “);
    scanf(“%d”,&num1);
    printf(“Enter the Ending number : “);
    scanf(“%d”,&num2);

    for(i=num1;i<=num2;i++){

    if(i%2==0){

    printf(" %d ",i);
    }

    }

    }

  2. Casey Hurley says:

    Well, this substance has just blown up my mind!
    So many interesting facts and critical examples that I am astonished and highly pleased with the information you give us.
    The topic is burning as well, so I suggest I will read it as I did
    with this article https://allbdlive.com/fartknocker/. Last but not least is I can share this information with friends
    of mine and get their pleasure from the specified material
    also. Let such info be!

Cancel reply

Leave a Reply to Anant kumar agrahari sultanpur

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>