Write a function FindMax() that will accept three variables ( firstnum , secnum
ID: 2083548 • Letter: W
Question
Write a function FindMax()that will accept three variables
(firstnum, secnum, and max), each is of type int. The first and second variables will have a “copy” of their contents sent to the function while the third variable will have its “address” sent to Findmax. Write a program that prompts the user for the first and second numbers and then sends these values along with the variable max’s address to the function. Inside the function, determine which of the two numbers is the larger and place it into max. Hint: A reference to max will have to be accepted by FindMax().
Explanation / Answer
#include <iostream>
using namespace std;
void FindMax(int a,int b,int *max)
{
if(a>b)
{
*max=a;
}
else
{
*max=b;
}
}
int main() {
int firstNUM=0, secNUM=0;
int max;
cout<<" Enter two number : ";
cin>>firstNUM>>secNUM;
FindMax(firstNUM,secNUM,&max);
cout<<" maximum of two is: "<<max;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.