Print the odd and even numbers using While Loop in C


This program is about print the odd and even numbers upto given limits using While Loop

Source Code

#include<stdio.h>
int main()
{
  int i=1,n,even=0,odd=0;
   printf("\nEnter the Ending value:");
   scanf("%d",&n);
   printf("\nEven numbers:");
   while(i<=n)
   {
      if(i%2==0)
      {
        printf("\n%d",i);
        even++;
      }
      i++;
   
   }
   printf("\nOdd numbers:");
   i=1;
   while(i<=n)
   {
     if(i%2==1)
     {
        printf("\n%d",i);
        odd++;
     }
     i++;
   }
   printf("\nTotal even numbers:%d",even);
   printf("\nTOtal odd numbers:%d",odd);
   return 0;
}
To download raw file Click Here

Output

Enter the Ending value:10
Even numbers:
2
4
6
8
10
Odd numbers:
1
3
5
7
9
Total even numbers:5
Total odd numbers:5


List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C


Learn All in Tamil © Designed & Developed By Tutor Joes