C++ Program for Selection sort

C++ Program for Selection sort .

/**************************************************************	
	Author: Arun Vishnu M V
	Web: www.arunmvishnu.com
	Description: C++ Program for Selection sort .
***************************************************************/
#include<conio.h>   	
#include<iostream.h> 
#include<process.h>  
 
void main()
{
	int array[100],n,i,j,temp;
	clrscr();
	cout<<"How many numbers--> ";
	cin>>n;
	cout<<"Enter "<<n<<" numbers\n";
	for(i=0;i<n;i++)
		cin>>array[i];
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
			if(array[i]>array[j])
			{
				temp=array[i];
				array[i]=array[j];
				array[j]=temp;
			}
	}
	cout<<"\nArray is sorted in ascending order.\n";
	for(i=0;i<n;i++)
		cout<<array[i]<<"   ";
	getch();
}
//---------------------- END--------------------

You may also like...

1 Response

  1. akash ruhil says:

    thank you, so much sir for all of your programs…… thanx a lot..

Leave a Reply

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