dou sbould have the heltionrtntuse the flnothe code to your directory cp /net/da
ID: 3887459 • Letter: D
Question
Explanation / Answer
#include<iostream>
using namespace std;
int main()
{
int size, arr[50], i, j, temp;
cout<<"Enter The number of elements (Array Size) : ";
cin>>size;
cout<<"Enter values : ";
for(i=0; i<size; i++)
{
cin>>arr[i];
}
cout<<"Sorting(Ascending Order) the above list using selection sort... ";
for(i=0; i<size; i++)
{
for(j=i+1; j<size; j++)
{
//asending order chage > symbol to < for descening order.
if(arr[i]>arr[j])
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
cout<<"Sorted array. : ";
for(i=0; i<size; i++)
{
cout<<arr[i]<<" ";
}
return 0;
}
OUTPUT
Enter The number of elements (Array Size) : 5
Enter values : 11 60 22 5 10
Sorting(Ascending Order) the above list using selection sort...
Sorted array. :
5 10 11 22 60
Note:- If you want to sorted array in desceinding order just change this line if(arr[i]>arr[j]) to if(arr[i]<arr[j])
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.