Sum and Product of minimum and maximum element of an Array | C ++ program for the above approach ; Function to get sum ; Function to get product ; Driver Code ; sorting the array ; min element would be the element at 0 th index of array after sorting ; max element would be the element at ( n - 1 ) th index of array after sorting
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findSum ( int minEle , int maxEle ) { return minEle + maxEle ; } int findProduct ( int minEle , int maxEle ) { return minEle * maxEle ; } int main ( ) { int arr [ ] = { 12 , 1234 , 45 , 67 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; sort ( arr , arr + n ) ; int minEle = arr [ 0 ] ; int maxEle = arr [ n - 1 ] ; cout << " Sum ▁ = ▁ " << findSum ( minEle , maxEle ) << endl ; cout << " Product ▁ = ▁ " << findProduct ( minEle , maxEle ) ; return 0 ; }