Answer to Question #212087 in C++ for Josephine

Question #212087

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):


1
Expert's answer
2021-06-30T03:16:10-0400
#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;	
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS