C++ program to print multiplication of largest and smallest element of array
Take inputs from the user. Sort the array in ascending order then the smallest element will be at index position 0 and the largest element will be at index position size-1. Take a variable "mul" to store the multiplication of the largest and smallest element. Print the multiplication.
Code
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; //array size
cin>>n;
int a[n]; //array declaration
for(int i=0;i<n;i++){ //reading the array elements
cin>>a[i];
}
sort(a,a+n); //sorting the array in ascending order
int mul=a[0]*a[n-1]; //multiplying the largest and smallest element
cout<<"The multiplication of largest and smallest element of array is: "<<mul; //Printing the multiplication
return 0;
}
Input
5
4 8 6 2 7
Output
The multiplication of largest and smallest element of array is: 16
0 Comments