Challenge: Biggest of Three

Lab C++ Beginner 10 points

Write a function int maxOfThree(int a, int b, int c) that returns the biggest of three numbers. Read three numbers in main and print the result of your function.

Input

Three integers.

Output

The biggest one.

Example

Input

3 9 4

Output

9
Sample input available Sample output available
Editor
C++

Hints

Start by assuming a is the biggest.

Compare with b and then with c, updating your answer.

Solution explanation

Keep the best answer so far in a variable and compare it with each of the others.

Show solution
#include <iostream>
using namespace std;

int maxOfThree(int a, int b, int c) {
    int biggest = a;
    if (b > biggest) {
        biggest = b;
    }
    if (c > biggest) {
        biggest = c;
    }
    return biggest;
}

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << maxOfThree(a, b, c) << "\n";
    return 0;
}
Output
Answer
HOME LABS COMMUNITY DASHBOARD