Skip to content

C Program to sort all even and odd numbers from the array

by admin on March 16th, 2012

This program in made in the C programming language. We will enter the elements in the array. Then the program code will sort all the even and odd numbers and will display the output. The code of the C program is as follows -

/* C program to find all the odd and even numbers in an array */
#include<stdio.h>
#include<conio.h>
void main()
{
     int ar[100],i,n;

     printf("Enter the size of the array \n");
     scanf("%d",&n);

     printf("Enter the elements of the array \n");
     for(i=0; i<n; i++)
     {
           scanf("%d",&ar[i]);
     }

     printf("Even numbers in the array are - ");
     for(i=0;i<n;i++)
     {
           if(ar[i]%2==0)
           {
                 printf("%d \t",ar[i]);
           }
     }

     printf("\n Odd numbers in the array are - ");
     for(i=0;i<n;i++)
     {
           if(ar[i]%2!=0)
           {
                 printf("%d \t",ar[i]);
           }
     }
     getch();
}

Logic - Logic of this C program is that the one for loop is used to sort all the even elements from the array and print them.  Similarly another for loop is used to sort all the odd elements and print them.
Input – 10   12    55   23   11
Output -
Odd numbers are – 55   23   11
Even numbers are – 10   12

3 Comments
  1. mitesh solanki permalink

    good solution of my question, thks for u……..

  2. I am sanjay from B.C.A student your solution is right

  3. MAXMILLIAN AFANGA permalink

    NICE CODE

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS