Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int max(int* a, int n)
- {
- int tmp = a[0], tmp_i = 0;
- for(int i = 1; i < n; i++)
- {
- if(a[i] > tmp)
- {
- tmp = a[i];
- tmp_i = i;
- }
- }
- return tmp_i;
- }
- int main()
- {
- int n_a, n_b;
- std::cout << "A[] size:\n";
- std::cin >> n_a;
- int *A = (int*)malloc(sizeof(int) * n_a);
- std::cout << "Enter A[]:\n";
- for(int i = 0; i < n_a; i++)
- std::cin >> A[i];
- std::cout << "B[] size:\n";
- std::cin >> n_b;
- int *B = (int*)malloc(sizeof(int) * n_b);
- std::cout << "Enter B[]:\n";
- for(int i = 0; i < n_b; i++)
- std::cin >> B[i];
- int half = (!(n_a % 2)) ? n_a/2 : n_a/2 + 1;
- int a_i = max(&A[half], half) + half;
- std::cout << "Max of the second half of A[]: " << "A[" << a_i << "] = " << A[a_i] << std::endl;
- int third = n_b / 3;
- int b_i = max(&B[third], third) + third;
- std::cout << "Max of the second third of B[]: " << "B[" << b_i << "] = " << B[b_i];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement