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
2 Comments
→
good solution of my question, thks for u……..
I am sanjay from B.C.A student your solution is right