Program to sort array as odd and even numbers
Program:
#include<stdio.h>
void main()
{
int i,j=0,k=0,a[5],odd[5],even[5];
printf("Enter int array: \n");
for(i=0;i<5;i++)
{
scanf("%d",&a[i]);
if(a[i]%2==0)
{
even[j]=a[i];
j=j+1;
}
else
{
odd[k]=a[i];
k=k+1;
}
}
printf("\nTheir are %d even numbers
and %d odd numbers!!!",j,k);
printf("\nOdd number's array is:
");
for(i=0;i<k;i++)
{
printf("\n%d",odd[i]);
}
printf("\nEven number's array is:
");
for(i=0;i<j;i++)
{
printf("\n%d",even[i]);
}
}
Output:
Note:
We can't use float or double array here as modulo(%) is not defined for them.
No comments:
Post a Comment