Write a C program to find the maximum number between three numbers

Description: Take three numbers as input and print the largest one.

Hint:

  • Compare the numbers using the >= and && operators.

C program to find the largest of three numbers

#include <stdio.h>

int main(void) {
    int a, b, c, max;

    printf("Enter three numbers: ");
    scanf("%d %d %d", &a, &b, &c);

    if (a >= b && a >= c) {
        max = a;
    } else if (b >= a && b >= c) {
        max = b;
    } else {
        max = c;
    }
    printf("Largest = %d\n", max);
    return 0;
}

Output:

Output of the above program is

Enter three numbers: 12 45 30
Largest = 45

How it works

  • We check if a is greater than or equal to both others. If not, we check b, and otherwise c must be the largest.
  • Using >= also works when two numbers are equal.

Learn more about the similar topics:
Tutorials
C If Else Statement
C Else If Ladder and Nested If
C Switch Statement
C While Loop
C Do While Loop
C For Loop
C Nested Loops
Exercises & Assignments
Write a C program to check whether a number is even or odd
Write a C program to check whether a user is eligible to vote or not
Write a C program to check whether an alphabet is vowel or consonant
Write a C program to find the maximum number between three numbers
Write a C program to check whether a number is positive, negative or zero
Write a C program to calculate an electricity bill
Write a C program to print 1 to 10 numbers using a while loop
Interview Questions & Answers
What is the difference between while and do while loop in C?
What is the difference between break and continue in C?
How to check if a number is prime in C?
How to find the factorial of a number in C?