C++ Program to sort a list of nos. (ascending order)

//sort a list(ascending)
#include <iostream>
using namespace std;
int main()
{	
	int i,n,j;
	double temp;
	cout<<"Enter the size of the list"<<endl;
	cin>>n;
	cout<<"Enter the elements of the list\n";
	double a[n];
	for (i=0;i<n;i++)
	{
	cin>>a[i];
	}
	for (i=0;i<n;i++)
	{
		for (j=i;j<n;j++)
		{
			if (a[i]>a[j])
			{
				temp=a[i];
				a[i]=a[j];
				a[j]=temp;
			}
		}
	}
	cout<<"\nThe sorted list is \n";
		for (i=0;i<n;i++)
	{
	cout<<a[i]<<endl;
	}
	return 0;
}

[wpedon id="7041" align="center"]

5 thoughts on “C++ Program to sort a list of nos. (ascending order)

  1. i followed exactly the same program as above but i couldnt get the exact result.

  2. Manas;

    Have you ever worked with light spectra for content analysis; that is, to dissect reflected light so as to get a list of a sample’s constituent atomic elements? I guess that would be spectral analysis.

    1. No, not exactly. I have done some spectroscopy but not in the way you mentioned.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.