The document contains C++ code to arrange elements of an array in ascending and descending order using selection sort. It first takes input from the user for the number of elements and values of the array. It then sorts the array in descending order using a selection sort algorithm and prints it. Following this, it again sorts the same array in ascending order using selection sort and prints the output.
The document contains C++ code to arrange elements of an array in ascending and descending order using selection sort. It first takes input from the user for the number of elements and values of the array. It then sorts the array in descending order using a selection sort algorithm and prints it. Following this, it again sorts the same array in ascending order using selection sort and prints the output.
The document contains C++ code to arrange elements of an array in ascending and descending order using selection sort. It first takes input from the user for the number of elements and values of the array. It then sorts the array in descending order using a selection sort algorithm and prints it. Following this, it again sorts the same array in ascending order using selection sort and prints the output.
The document contains C++ code to arrange elements of an array in ascending and descending order using selection sort. It first takes input from the user for the number of elements and values of the array. It then sorts the array in descending order using a selection sort algorithm and prints it. Following this, it again sorts the same array in ascending order using selection sort and prints the output.
cout<<"NAME: Ayush chitra\nROLL: 3554\n\nARRANGING ELEMENTS OF AN ARRAY IN ASCENDING ORDER AND DESCENDING ORDER BY SELECTION SORT"; int n,i,j,c; cout<<"\nenter the number of elements in array :"; cin>>n; int A[n]; for( i=0;i<n;i++){ cout<<"enter the element at A["<<i<<"]: "; cin>>A[i]; } for(i=0;i<n-1;i++){ for(j=i+1;j<n;j++){ if(A[i]<A[j]){ c=A[i]; A[i]=A[j]; A[j]=c;}}} cout<<"your array in descending order is\n"; for( i=0;i<n;i++){ cout<<A[i]<<" ";} for(i=0;i<n-1;i++){ for(j=i+1;j<n;j++){ if(A[i]>A[j]){ c=A[i]; A[i]=A[j]; A[j]=c;}}} cout<<"\nyour array in ascending order is\n"; for( i=0;i<n;i++){ cout<<A[i]<<" ";} return 0;}