Home » NO IDEA » Sorting the array in descending order

Sorting the array in descending order

Blog Stats

  • 15,880 hits
December 2013
M T W T F S S
« Oct   Jan »
 1
2345678
9101112131415
16171819202122
23242526272829
3031  
//Develop a ‘C’ program to sort ‘N’ numbers in ascending order. 
#include<stdio.h>
#define N 5  //change the value of N here 
int main()
{
	//sorting can be done in many ways
	// sorting here used is bubble sort 
	int a[N],i,j;

	printf("\n Enter the array  consists of %d elements",N);
	for(i=0;i<N;i++)
	{
		scanf("%d",&a[i]);
	}
	for(i=0;i<N;i++)
	{
	for(j=i+1;ja[j])
		{
			int t=a[i];
			a[i]=a[j];
			a[j]=t;
		}
	}
	}
	printf("\n Sorted Elements in the ascending order\n");
	for(i=N-1;i>=0;i--)
	{
		printf("%d\n",a[i]);
	}
return 0;
}
Advertisements

1 Comment

  1. […] write a c program to sort ‘N’ numbers in ascending order […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: