The program below prints an array in descending order.what changes can i make to print it in ascending order? thank you | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

The program below prints an array in descending order.what changes can i make to print it in ascending order? thank you

#include <iostream> using namespace std; const int n=5; int x[n]; int temp; int main() { cout<<"entr 5 no pliz:)"<<endl; for(int i=0;i<n;i++){ cin>>x[i]; cout<<x[i]<<endl; } for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ if(x[i]<x[j]){ temp=x[j]; x[j]=x[i]; x[i]=temp; } } } cout<<"the descending order is"<<endl; for(int i=0;i<n;i++){ cout<<x[i]<<endl; } return 0; }

10th Dec 2018, 7:46 PM
RiGeL
RiGeL - avatar
1 Answer
+ 3
「HAPPY TO HELP」 thank you, i also changed the '< 'to '>' in the if part and it worked too :)
10th Dec 2018, 7:54 PM
RiGeL
RiGeL - avatar