Solution to write a function that takes an array of integer as output as input and prints … - Sikademy
Author Image

Archangel Macsika

write a function that takes an array of integer as output as input and prints the second maximum difference between any two elements from an array

The Answer to the Question
is below this banner.

Can't find a solution anywhere?

NEED A FAST ANSWER TO ANY QUESTION OR ASSIGNMENT?

Get the Answers Now!

You will get a detailed answer to your question or assignment in the shortest time possible.

Here's the Solution to this Question


#include <bits/stdc++.h> using namespace std; int maxDiff(int arr[], int arr_size){ int max_diff = arr[1] - arr[0]; for (int i = 0; i < arr_size; i++) for (int j = i+1; j < arr_size; j++) if (arr[j] - arr[i] > max_diff) max_diff = arr[j] - arr[i]; return max_diff; } int main(){ int arr[] = {1, 2, 90, 10, 110}; int n = sizeof(arr) / sizeof(arr[0]); cout << "Maximum difference is " << maxDiff(arr, n); return 0; }

Related Answers

Was this answer helpful?

Join our Community to stay in the know

Get updates for similar and other helpful Answers

Question ID: mtid-3-stid-44-sqid-1057-qpid-53