C Program to Print Even and Odd Numbers From 1 to N Using While Loop
In this tutorial, we are going to see how to write a program to print even and odd numbers from 1 to n in C language using while loop. Considering we have an integer(N) and we need to print even and odd numbers from 1 to N using a C program.
There are four ways to check or print even and odd numbers in C, by using for loop, while loop, if-else, or by creating a function.
An even number is an integer exactly divisible by 2. Example: 0, 4, 8, etc.
An odd number is an integer that is not exactly divisible by 2. Example: 1, 3, 7, 15, etc.
Write a Program to Print Even and Odd Numbers From 1 To n in C Using While Loop
#include <stdio.h>
void main()
{
int i,last;
printf("Enter The Last Number : ");
scanf("%d",&last);
//While Loop
//Code For Even Number List
printf("\nEven Number List :\n ");
i=2;
while(i <= last)
{
printf(" %d",i);
i = i + 2;
}
//Code For Odd Number List
printf("\nOdd Number List :\n ");
i=1;
while(i <= last)
{
printf(" %d",i);
i = i + 2;
}
}
Output:
Enter The Last Number : 10 Even Number List : 2 4 6 8 10 Odd Number List : 1 3 5 7 9




