sort even and odd terms of an array

Program to sort even and odd terms of an array

#include < stdio.h>
#include < conio.h>
main()
{
int t,a[10],i,j,k;
clrscr();
printf("Enter the array");
for(i=0;i < 10;i++)
{
scanf("%d",&a[i]);
}
for(j=0;j < 10;j++)
{
for(i=0;i < 9-j;i++)
{
if(a[i]>a[i+1])
{
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
}}
for(i=0;i < 10;i++)
{
for(j=0;j < 9;j++)
{
if((a[j]%2==0)&&(a[j]%2)!=(a[j+1]%2))
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}}
printf("\nSorted Array\n");
for(i=0;i < 10;i++)
printf("%d\n",a[i]);
getch();
}

0 comments: