C Program to Print Even Numbers from 1 to N

C program to print even numbers from 1 to N (10, 100, 500, 1000); Through this tutorial, we will learn how to print even numbers from 1 to N (10, 100, 500, 1000) in the c program using for loop, while loop and function.

Algorithm and Programs to Print Even Numbers from 1 to N

Use the following algorithm and program to print even numbers from 1 to n in c:

  • Algorithm to Print Even Numbers from 1 to N
  • C Program to Print Even Numbers from 1 to N using For Loop
  • C Program to Print Even Numbers from 1 to N using While Loop
  • C Program to Print Even Numbers from 1 to N using Function

Algorithm to Print Even Numbers from 1 to N

Use the following algorithm to write a program to print even numbers from 1 to N (10, 100, 500, 1000); as follows:

  • Step 1: Start Program
  • Step 2: Read the number from user and store it in a.
  • Step 3: Iterate for or while loop according to a user input a number.
  • Step 4: Inside loop, use if with n % 2 == 0 condition to print even number.
  • Step 5: Stop Program

C Program to Print Even Numbers from 1 to N using For Loop

/* C Program to Print Even Numbers from 1 to N using For Loop and If */

#include<stdio.h>

int main()
{
  	int i, number;

  	printf("\n Please Enter the Maximum Limit Value : ");
  	scanf("%d", &number);

  	printf("\n Even Numbers between 1 and %d are : \n", number);
  	for(i = 1; i <= number; i++)
  	{
    	if ( i % 2 == 0 )
    	{
  			printf(" %d\n", i);
    	}
  	}

  	return 0;
}

The output of the above c program; as follows:

Please Enter the Maximum Limit Value : 10
Even Numbers between 1 and 10 are :
 2
 4
 6
 8
 10

C Program to Print Even Numbers from 1 to N using While Loop

#include<stdio.h>

int main()
{
  	int i = 2, number;

  	printf("\n Please Enter the Maximum Limit Value : ");
  	scanf("%d", &number);

  	printf("\n Even Numbers between 1 and %d are : \n", number);
  	while(i <= number)
  	{
		printf(" %d\n", i);
		i = i+2;
  	}

  	return 0;
}

The output of the above c program; as follows:

Please Enter the Maximum Limit Value : 15
Even Numbers between 1 and 15 are :
 2
 4
 6
 8
 10
 12
 14

C Program to Print Even Numbers from 1 to N using Function

/* C Program to Print Even Numbers from 1 to N using For Loop and If */

#include<stdio.h>


int evenNoList(no){

int i;

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

}

int main()
{
  	int number;

  	printf("\n Please Enter the Maximum Limit Value : ");
  	scanf("%d", &number);
    printf("\n Even Numbers between 1 and %d are : \n", number);
    evenNoList(number);
    return 0;
}

The output of the above c program; as follows:

Please Enter the Maximum Limit Value : 20
Even Numbers between 1 and 20 are :
 2
 4
 6
 8
 10
 12
 14
 16
 18
 20

Recommended C Programs

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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