Wednesday, 25 May 2016

Sorted Array By Slection Sorting In Dev C++


Sorted Array By Slection Sorting In Dev C++







C++ Code Is Given Blow
Just Click On Read More




#include<iostream>
#include<conio.h> 
using namespace std;
int main()
{
int a[5],i,j,temp,min;   
for(i=0;i<5;i++)
{
cout<<"Enter the value=";
cin>>a[i];
}
cout<<"Original values in array="<<endl;
for(i=0;i<5;i++)
{
cout<<a[i]<<"   ";
}
for(i=0;i<4;i++)
{
min=i;
for(j=i+1;j<5;j++)
{
if(a[j]<a[min])
min=j;
}
if(min!=i)
{
temp=a[i];
a[i]=a[min];
a[min]=temp;
}
}
cout<<"\nThe sorted array is:"<<endl;
for(i=0;i<5;i++)
{
cout<<a[i]<<"   ";
}
    return 0;
}

No comments: