Write a program that will accept an n integer from the user via the keyboard,
The dialog for this program should look as follows:
Enter number of integers to process: 3
Enter the integers: 7 20 17
Largest = 20
Smallest = 7
Median = 17
Do you want to try again? (y/n):
#include<iostream>
using namespace std;
int minimum(int first, int second,int third){
int min = first;
if(second<first && second<third){
min = second;
}
else if(third<first && third<second){
min = third;
}
return min;
}
int maximum(int first, int second,int third){
int max = first;
if(second>first && second>third){
max = second;
}
else if(third >first && third>second){
max = third;
}
return max;
}
double median(int first, int second,int third)
{
int med = second;
if (first < med) med = first;
if (third > med) med = third;
return med;
}
int main(){
int first;
int second;
int third;
int n;
cout<<"Enter number of integers to process:\t ";
cin>>n;
cout<<"Enter the integers:\t";
cin>>first;
cin>>second;
cin>>third;
cout<<"\n";
cout<<"The Largest= \t"<<maximum( first, second, third)<<endl;
cout<<"The Smallest= \t"<<minimum( first, second, third)<<endl;
cout<<"The Median= \t"<<median( first, second, third)<<endl;
char y;
cout<<"Do you want to continue? (y/n):"<<endl;
cin>>y;
if(y=='y'){
main();
}
return 0;
}
Comments
Leave a comment