Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int arr[100];
- int n, i,j, temp, tv;
- cout << "Nhap so phan tu cua mang: ";
- cin >> n;
- for (i = 0; i < n; i++)
- {
- cout << "Nhap vao phan tu thu " << i+1 << " cua mang:";
- cin >> arr[i];
- }
- // Sap xep day tang dan
- for (i = 0; i < n-1; i++)
- {
- for (j = i + 1; j < n; j++)
- {
- if (arr[i] > arr[j])
- {
- temp = arr[i];
- arr[i] = arr[j];
- arr[j] = temp;
- }
- }
- }
- // Tim so trung vi
- if (n % 2 == 0)
- {
- int a = n / 2;
- int b = a + 1;
- tv = (arr[a] + arr[b]) / 2;
- }
- if (n % 2 == 1)
- {
- int c = (n + 1) / 2 -1;
- tv = arr[c];
- }
- cout << "Day so sap xep theo thu tu tang dan: " << endl;
- for (i = 0; i < n; i++)
- {
- cout << arr[i] << endl;
- }
- cout << "So trung vi la: " << tv << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement