SHARE
TWEET

Câu 3: Có 1 mảng số nguyên không trùng có n phần tử, tìm 3..

Tan_Ngo Feb 27th, 2020 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int A[1000];
  6.     int n;
  7.     int max1, max2, max3;
  8.     cout << "Nhap vao so luong phan tu: ";
  9.     cin >> n;
  10.     for (int i = 0; i < n; i++)
  11.     {
  12.         cout << "Gia tri phan tu thu " << (i + 1) << ": ";
  13.         cin >> A[i];
  14.     }
  15.     max1 = A[0];
  16.     max2 = A[0];
  17.     max3 = A[0];
  18.     for (int i = 1; i < n; i++)
  19.     {
  20.         if (A[i] > max1)
  21.         {
  22.             max1 = A[i];
  23.         }
  24.     }
  25.     for (int i = 1; i < n; i++)
  26.     {
  27.         if (A[i] > max2 && A[i] < max1)
  28.         {
  29.             max2 = A[i];
  30.         }
  31.     }
  32.     for (int i = 1; i < n; i++)
  33.     {
  34.         if (A[i] > max3 && A[i] < max2)
  35.         {
  36.             max3 = A[i];
  37.         }
  38.     }
  39.     cout << max1 << "  " << max2 << "  " << max3 << endl;
  40.     system("pause");
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top