Advertisement
tuki2501

sap_xep.cpp

Jan 27th, 2021
610
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.   int n, a[100];
  6.   cout << "Nhap n: ";
  7.   cin >> n;
  8.   for (int i = 0; i < n; i++) {
  9.     cout << "Nhap a[" << i << "] = ";
  10.     cin >> a[i];
  11.   }
  12.   for (int i = 0; i < n - 1; i++)
  13.   for (int j = i + 1; j < n; j++) {
  14.     if (a[i] > a[j]) {
  15.       int temp;
  16.       temp = a[i];
  17.       a[i] = a[j];
  18.       a[j] = temp;
  19.     }
  20.   }
  21.   cout << "Mang a sau khi sap xep:\n";
  22.   for (int i = 0; i < n; i++) {
  23.     cout << a[i] << ' ';
  24.   }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement