Print and separate odd and even numbers using For Loop in C


This program is about to separate and print the odd and even numbers up to given limit using For Loop

Source Code

#include<stdio.h>
int main()
{
  int i,n,even=0,odd=0;
  printf("\nEnter the Ending value:");
  scanf("%d",&n);
  printf("\nEven numbers:");
  for(i=0;i<=n;i++)
  {
    if(i%2==0)
    {
      printf("\n%d",i);
      even++;
    }
  }
  printf("\nOdd numbers:");
  for(i=1;i<=n;i++)
  {
    if(i%2==1)
    {
      printf("\n%d",i);
      odd++;
    }
  }
  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: 8
Even numbers:
0
2
4
6
8
Odd numbers:
1
3
5
7
Total even numbers:5
Total odd numbers: 4

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