Nov
28
2008

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--------------------

Related Posts

Author: Arun Vishnu

1 Comment + Add Comment

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

Leave a comment

Archives

Highslide for Wordpress Plugin