Maximum of 3 Numbers: Rita is very happy about the successful completion of pattern game by her students. By that time, Disneyland project manager announced a Mini project related to mathematical calculations. Rita thought of taking up that Mini project and completing it with the help of her students. She took that project, and then she splits the project into separate modules and hands it over to each student. The first module is to find maximum among three numbers.
Rita instructed students to follow the function specification strictly. Rita allotted this function to Patrick.
Help Patrick to write a program to find the maximum of 3 numbers using functions.
Function Specification:
int findmaximum(int, int, int )
Input Format:
Input consists of 3 integers.
Output Format:
Refer sample input and output for formatting details.
Sample Input:
13
45
23
Sample Output:
45 is the maximum number
Function Definitions:
int findmaximum (int , int , int) |
Solution
#include <iostream>
using namespace std;
int findmaximum(int a, int b, int c)
{
if ((a > b) && (a > c))
return a;
else if ((b > c) && (b > a))
return b;
else
return c;
}
int main()
{
int a, b, c, d;
cin >> a;
cin >> b;
cin >> c;
d = findmaximum(a, b, c);
cout << d << " is the maximum number";
return 0;
}
#include <iostream>
using namespace std;
int findmaximum(int a, int b, int c)
{
int max = a;
if (b > max)
{
max = b;
}
if (c > max)
{
max = c;
}
return max;
}
int main()
{
int a, b, c;
cin >> a >> b >> c;
cout << findmaximum(a, b, c) << " is the maximum number" << endl;
return 0;
}