#include using namespace std; void NhapMang(float a[100], int& n) { cout << "Nhap chieu dai mang:"; do { cin >> n; } while (n <= 0); for (int i = 0; i < n; i++) { cout << "a[" << i << "] = "; cin >> a[i]; } } void XuatMang(float a[100], int n) { for (int i = 0; i < n; i++) { cout << a[i] << "\t"; } } int MaxPosition(float a[100], int n) { float max = a[0]; int position = 0; for (int i = 1; i < n; i++) { if (a[i] > max) { max = a[i]; position = i; } } return position; } int MinPosition(float a[100], int n) { float min = a[0]; int position = 0; for (int i = 1; i < n; i++) { if (a[i] < min) { min = a[i]; position = i; } } return position; } double Max(float a[100], int n) { float max1 = -10000; for (int i = 0; i < n; i++) { if (abs(a[i]>=max1)) { max1 = abs(a[i]); } } float max2 = -10000; for (int i = 0; i < n; i++) { if (abs(a[i]) >= max2 && abs(a[i]) != max1) { max2 = abs(a[i]); } } return max1 + max2; } void main() { float m[100]; int k; NhapMang(m, k); cout << endl; int x; cout << "===============================Menu=============================" << endl; cout << " 1: Xuat mang" << endl; cout << " 2: Tim vi tri phan tu lon nhat va nho nhat trong mang" << endl; cout << " 3: Tinh tong lon nhat cua 2 phan tu tuyet doi trong mang " << endl; cout << " 4: Exit " << endl; cout << " ===============================================================" << endl; do { cout << "Nhap so cau:"; cin >> x; switch(x) { case 1: XuatMang(m, k); break; case 2: cout << endl; cout << "Vi tri phan tu lon nhat:" << MaxPosition(m, k); cout << endl; cout << "Vi tri phan tu nho nhat:" << MinPosition(m, k); cout << endl; break; case 3:cout << "Sum = " << Max(m, k) << endl; break; default: return; } } while (x>0&&x<4); }