Advertisement
Guest User

.

a guest
Feb 23rd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main(){
  4.  
  5. int a[50], n, i, aux;
  6.  
  7. cout << "N = ";
  8. cin >> n;
  9.  
  10. cout << endl;
  11.  
  12. for ( i = 1; i <= n; i++ ) {
  13. cout << "a["<<i<<"] = ";
  14. cin >> a[i];
  15. }
  16. cout << endl;
  17.  
  18. cout << "Tabloul introdus: " << endl << endl;
  19.  
  20. for ( i = 1; i <= n; i++ ) {
  21. cout << a[i] << " ";
  22. }
  23. cout << endl << endl;
  24.  
  25. int ok;
  26. int j;
  27.  
  28. do {
  29. ok = 1;
  30.  
  31. for ( i = 0; i < n; i++ )
  32. for ( j = i+1; j <= n; j++ )
  33. if ( a[i] < a[j] ) {
  34. aux = a[j];
  35. a[j] = a[i];
  36. a[i] = aux;
  37. ok = 0;
  38. }
  39. }
  40.  
  41.  
  42. while ( ok==0 );
  43.  
  44. do {
  45. ok = 1;
  46.  
  47. for ( i = 1; i <= n; i++ )
  48. for ( j = i+1; j <= n; j++ )
  49. if ( a[i] > a[j] ) {
  50. aux = a[j];
  51. a[j] = a[i];
  52. a[i] = aux;
  53. ok = 0;
  54. }
  55. }
  56.  
  57.  
  58.  
  59. while ( ok==0 );
  60.  
  61.  
  62. cout << "Tabloul sortat: " << endl;
  63.  
  64. for ( i = 1; i <= n; i++ ) {
  65. cout << a[i] << " ";
  66. }
  67.  
  68. cout << endl;
  69.  
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement