Answer to Question #274744 in C++ for Mod

Question #274744

Write functions which respectively calculate the sum, product, minimum, maximum, average of two integers A and B. Use these functions in a program.


1
Expert's answer
2021-12-02T14:15:45-0500


#include <iostream>
#include <string>
using namespace std;
int calculateSum(int A,int B){
	return A+B;
} 
int calculateProduct(int A,int B){
	return A*B;
}
int calculateMinimum(int A,int B){
	if(B>A){
		return A;
	}
	return B;
}
int calculateMaximum(int A,int B){
	if(B>A){
		return B;
	}
	return A;
}
float calculateAverage(int A,int B){
	return (((float)A+(float)B)/2.0);
}


int main()
{
	int A,B;
	cout<<"Enter A: ";
	cin>>A;
	cout<<"Enter B: ";
	cin>>B;


	cout<<"Sum: "<<calculateSum(A,B)<<"\n";
	cout<<"Product: "<<calculateProduct(A,B)<<"\n";
	cout<<"Minimum: "<<calculateMinimum(A,B)<<"\n";
	cout<<"Maximum: "<<calculateMaximum(A,B)<<"\n";
	cout<<"Average: "<<calculateAverage(A,B)<<"\n";
	system("pause");
	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