c-programs-basics
We are going to write a c program to print the list of even and odd numbers. we can do this by using loops such as while loop, do while loop and for loop.

C Program To Print Even and Odd Numbers Using While Loop
#include<stdio.h>
#include<conio.h>
void main()
{
 int n,last;
 clrscr();

 printf("\n Enter Last Number : ");
 scanf("%d",&last);

 //While Loop

 //Code For Even Number List
 printf("\n Even Number List :\n ");

 n=2;
 while(n<=last)
 {
  printf(" %d",n);
  n=n+2;
 }

 //Code For Odd Number List
 printf("\n\n Odd Number List :\n ");

 n=1;
 while(n<=last)
 {
  printf(" %d",n);
  n=n+2;
 }

 getch();

}

Output: 
Output-C-Program-Even-Odd-Number-List









In the above program, 
  • We have initialized the values of even and odd numbers from 2 and 1 respectively.
  • Then we have printed each number and increased it by two in the next iteration using loop to get the next even or odd number respectively.

Display Even and Odd Number List Using Do While Loop

When using do while loop the condition is declared after the first iteration as shown below.
#include<stdio.h>
#include<conio.h>
void main()
{
 int n,last;
 clrscr();

 printf("\n Enter Last Number : ");
 scanf("%d",&last);

 // Do_While Loop

 // Code for Even Number list
 printf("\n Even Number List :\n ");

 n=2;
 do
  {
   printf(" %d",n);
   n=n+2;

  } while(n<=last);

 // Code for Odd Number List
 printf("\n\n Odd Number List :\n ");

 n=1;
  do
  {
   printf(" %d",n);
   n=n+2;

  } while(n<=last);

 getch();
 }

C Program To Print Even and Odd Numbers Using For Loop

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

 printf("\n Enter Last Number : ");
 scanf("%d",&last);

 //  For loop
 // Code For Even Number List
 printf("\n Even Number List :\n ");

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

 // Code For Odd Number List
 printf("\n\n Odd Number List :\n ");

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

 getch();

}

We can also use the method we used to find even or odd number in c to print the list of odd and even numbers.
C Program To Print Even and Odd Numbers
#include<stdio.h>
#include<conio.h>
void main()
{
 int n,i,last;
 clrscr();

 printf("\n Enter Last Number : ");
 scanf("%d",&last);

 printf("\n Even Number List :\n ");

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

 printf("\n\n Odd Number List :\n ");

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

  getch();
}

This way we can print even and odd numbers list in c programming.