Answer to Question #261288 in C++ for dana

Question #261288

Write a C++ program that prompts the user to enter an even integer N which represents how many numbers he/she wants to enter. The program then reads N decimal numbers and finds the minimum number in the first half and the maximum number in the second half.


1
Expert's answer
2021-11-05T00:34:01-0400
#include <bits/stdc++.h>
using namespace std;
void findMax(int arr[], int n)
{
 
    int max1 = INT_MIN;
    int mid = n / 2;
 
    for (int i = 0; i < mid; i++)
        max1 = max(max1, arr[i]);
 
    if (n % 2 == 1)
        max1 = max(max1, arr[mid]);
 
    int max2 = INT_MIN;
    for (int i = mid; i < n; i++)
        max2 = max(max2, arr[i]);
 
    cout << max1 << ", " << max2;
}
 
int main()
{
	int N;
	int i,arr[10]; 
    cout<<"Enter an even number N: ";
    cin>>N;
    cout<<"Enter 10 elements:"; 
    for(i=0;i<10;++i) 
        cin>>arr[i];
    int nn = sizeof(arr) / sizeof(arr[0]);
 
    findMax(arr, nn);
 
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS