Challenge: Biggest of Three

Lab C Beginner 10 points

Write a function int max3(int a, int b, int c) that returns the biggest of three numbers. In main, read three numbers and print the result of max3.

Input

Three integers.

Output

The biggest one.

Example

Input

3 9 4

Output

9
Sample input available Sample output available
Editor
C

Hints

Start with biggest = a.

Compare it with b, then with c, and update it when you find a bigger one.

Solution explanation

We keep the biggest value seen so far and replace it whenever a bigger one comes along.

Show solution
#include <stdio.h>

int max3(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;
    scanf("%d %d %d", &a, &b, &c);
    printf("%d\n", max3(a, b, c));
    return 0;
}
Output
Answer
HOME LABS COMMUNITY DASHBOARD