Answer:
Following are the code to this question:
#include<iostream>//defining header file
using namespace std;
int main ()//defining main method
{
int x[20], n, i, maximum, minimum;//defining an integer array x and another integer variable
cout <<"Enter the number of element you want to insert: ";//print message
cin >>n;//input size value from user end
if(n>20)//defining if block that check n is greater then 20
{
cout <<"The size of array should not exceed 20 element";//print message
return 0;//return 0
}
else//defining else block
{
cout<<"Enter array value: ";//print message
for(i=0;i<n;i++)//defining for loop
cin>>x[i];//defining for loop for input array value
maximum =x[0];//defining maximum variable that hold array value
for (i=0;i<n;i++)//defining for loop for check value
{
if(maximum<x[i])//defining if block to check maximum value
{
maximum=x[i];//hold maximum value
}
}
minimum=x[0];//use minimum variable to hold array value
for (i=0;i<n;i++)//defining for loop to hold minimum value
{
if (minimum>x[i])//defining if block to check minimum value
minimum =x[i];//hold minimum value
}
cout << "Maximum element : " << maximum ;//print maximum value
cout << "Minimum element : " << minimum ;//print minimum value
return 0;
}
}
Output:
Enter the number of element you want to insert: 7
Enter array value:
8
6
22
13
98
554
3
Maximum element : 554
Minimum element : 3
Step-by-step explanation:
In the above-given program, an integer array "x", and four integer variable "n, i, maximum, and minimum" is defined, which uses the if block to check the size of the array.
In the else block, it inputs the array value from the user end and after input value, it uses the conditional statement to check the "maximum and minimum" value in its variable and print its value.