#include<bits/stdc++.h>
using namespace std;
int main()
{
int i, j, min_indx, n;
cout << "Enter Array Element Number :: ";
cin >> n;
int a[n];
cout << "Enter Array Element :: ";
for(i=0;i<n;i++)
{
cin >> a[i];
}
for(i=0;i<n-1;i++)
{
min_indx = i;
for(j=i+1;j<n;j++)
{
if(a[j] < a[min_indx])
{
min_indx = j;
}
}
swap(a[min_indx], a[i]);
}
cout << endl << "After Sorting :: ";
for(i=0;i<n;i++)
cout << a[i] << " ";
cout << endl;
return 0;
}
using namespace std;
int main()
{
int i, j, min_indx, n;
cout << "Enter Array Element Number :: ";
cin >> n;
int a[n];
cout << "Enter Array Element :: ";
for(i=0;i<n;i++)
{
cin >> a[i];
}
for(i=0;i<n-1;i++)
{
min_indx = i;
for(j=i+1;j<n;j++)
{
if(a[j] < a[min_indx])
{
min_indx = j;
}
}
swap(a[min_indx], a[i]);
}
cout << endl << "After Sorting :: ";
for(i=0;i<n;i++)
cout << a[i] << " ";
cout << endl;
return 0;
}
Comments
Post a Comment