Back
Search_Max.cpp
Save
// Search_Max.cpp #include
using namespace std; float searchMax(float a[], int l, int r) { if (r == l) return a[l]; else { int m = (l + r) / 2; float max1 = searchMax(a, l, m); float max2 = searchMax(a, m + 1, r); if (max1 > max2) return max1; return max2; } } int main() { float a[] = {1.2, 3.4, 4.5, 9.1, 6.3, 7.2, 5.4, 4.6, 4.9, 8.5, 9.9, 0.5, 6, 8, 10.6}; cout << "Gia tri lon nhat la: " << searchMax(a, 0, 14) << endl; return 0; }