Thursday, July 7, 2011

Sorting in C - By Ascending

And finally i come up with a basic of C programmer for new buddies.Hope it might be useful.

I had given 5 values in the array to be simple.

#include
#include
int main()
{
int i,j,temp;
int a[5]={-123,34,14,87,45};
printf("SORTING PROGRAM IN ASCENDING\n");
for(i=0;i<5;i++)
{
for(j=i+1;j<5;j++)
{
if(a[i]<=a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
} for(i=0;i<5;i++)
printf("%d\n",a[i]);
getch();
}

No comments:

Post a Comment