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

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

admin has written 2 articles

8 thoughts on “C Program to sort all even and odd numbers from the array

  1. ishu mishra says:

    bubble sort is a sorting in which we compare consecutive items stored in a particular array after compairing it smallst one will be shifted left & other will be in ri8 like this we go further

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>