C program to display even numbers upto n

Write a C program to print even numbers upto n. Write a C program to print even numbers upto a given number n.

C Program to Display Even Numbers

/* Aim: Write a program to accept an integer n and display all even numbers up-to n */

#include <stdio.h>
int main()
{  
	int i,n;
 
	printf("\n Enter any number:- ");
	scanf("%d",&n);
 
	printf("\n The even numbers upto %d are:- \n \n",n);
 
	for(i=1;i<=n;i++)
	{
		if (i%2==0)
		printf(" %d",i);
	}

	return 0;
}

Output:

 Enter any number:- 20

 The even numbers upto 20 are:- 

 2 4 6 8 10 12 14 16 18 20