Breaking Posts

6/trending/recent

Hot Widget

Type Here to Get Search Results !

C++ Programming Code for Selection Sort.

C++ Programming Code for Selection Sort.

Selection Sort
/* C++ Program - Selection Sort */		
#include<iostream.h>
#include<conio.h>
void main()
{
	clrscr();
	int size, arr[50], i, j, temp;
	cout<<"Enter Array Size : ";
	cin>>size;
	cout<<"Enter Array Elements : ";
	for(i=0; i<size; i++)
	{
		cin>>arr[i];
	}
	cout<<"Sorting array using selection sort...\n";
	for(i=0; i<size; i++)
	{
		for(j=i+1; j<size; j++)
		{
			if(arr[i]>arr[j])
			{
				temp=arr[i];
				arr[i]=arr[j];
				arr[j]=temp;
			}
		}
	}
	cout<<"Now the Array after sorting is :\n";
	for(i=0; i<size; i++)
	{
		cout<<arr[i]<<" ";
	}
	getch();
}

Output:-



Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.