+ 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; }
1 Odpowiedź
+ 3
「HAPPY TO HELP」 thank you, i also changed the '< 'to '>' in the if part and it worked too :)