Maximum of 3 numbers: Mrs. Anitha , our favourite Maths teacher wanted to teach her new batch of students to find maximum among three numbers.
Write a program to accept 3 integers and find maximum among 3 numbers using functions and pointers.
Function Specification:
int maximum(int *a,int *b, int *c)
This function returns the maximum among 3 numbers.
Input Format:
Input consists of 3 integers.
Output Format:
Refer the sample output.
[All text in bold corresponds to input and the rest corresponds to output.]
Sample Input and Output :
Enter the value of a
5
Enter the value of b
6
Enter the value of c
2
Maximum element is 6
Solution
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int a, b, c;
cout << "Enter the value of a\n";
cin >> a;
cout << "Enter the value of b\n";
cin >> b;
cout << "Enter the value of c\n";
cin >> c;
if (a > b && a > c)
{
cout << "Maximum element is " << a;
}
else if (b > a && b > c)
{
cout << "Maximum element is " << b;
}
else
{
cout << "Maximum element is " << c;
}
return 0;
}
Happy Learning – If you require any further information, feel free to contact me.