dirtydevil123

sorting descending order

Jul 3rd, 2021 (edited)
655
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int a , b=0;
  8.     cout << "enter array size " ;
  9.     cin>>a;
  10.     int x[a+2];
  11.  
  12.  
  13.     for(int i;i<a;i++){
  14.         cin>>x[i];
  15.     }
  16.     cout<<" array is : ";
  17.     for(int j;j<a;j++ ){
  18.         cout<<x[j]<<" ";
  19.     }
  20.     cout<<endl;
  21.     cout<<endl;
  22.  
  23.     //sort(x, x + a, greater<int>());
  24.  
  25.     for(int i=0;i<a;i++)
  26.     {
  27.         for(int j=i+1;j<a;j++)
  28.         {
  29.             if(x[i]<x[j])
  30.             {
  31.                 b =x[i];
  32.                 x[i]=x[j];
  33.                 x[j]=b;
  34.  
  35.             }
  36.         }
  37.     }
  38.  
  39.  
  40.     cout<<" In descending order : "<<endl;
  41.     cout<<endl;
  42.     cout<<" array is : ";
  43.     for(int k;k<a;k++ ){
  44.         cout<<x[k]<<" ";
  45.     }
  46.  
  47.     return 0;
  48. }
  49.  
Add Comment
Please, Sign In to add comment