Roll NO 3554

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

#include<iostream>

using namespace std; int main(){


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;}

You might also like