Respuesta :
Answer:
// This program is written in C++
// It sorts array of n distinct elements in ascending order
// Comments are used for explanatory purpose
// Program starts here
#include <iostream>
using namespace std;
// Declare a maximum of 50
#define MAX 50
int main()
{
//The next line declares the array of 50 maximum integers
int Readln[MAX];
// The next line declares length of array
int n;
int temp;
// Prompt user to enter length of array
cout<<"Length of Array: ";
cin>>n;
//Check if length falls within range of 2 to MAX
while (n<2 || n>MAX)
{
cout<<"Array must have at least 2 elements and can't be more than "<<MAX<<endl;
}
// The next line declares an input element
int digit;
// The next loop statement accepts distinct array elements
for(int i=0; i<len;i++)
{
cout<<"Enter element ["<<i+1<<"] ";
cin>>digit;
// Check if digit is non-negative and less than 50; repeat until element is within range
while (digit<0 || n>49)
{
cout<<"Acceptable range is 0 to 49";
cin>>digit;
}
Readln[i] = digit;
}
//The next iteration sorts the array
for(i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(Readln[i]>Readln[j])
{
// Swap Elements
temp =Readln[i];
Readln[i]=arr[j];
Readln[j]=temp;
}
}
}
// The next line prints array elements
for(i=0;i<n;i++)
cout<<Readln[i]<<"\t";
cout<<endl;
return 0;
}
// End of program