Find the Biggest of Three Numbers using C


In this tutorial, we will learn how to find out the largest number out of three numbers using simple if-else conditions in C programming Language.

Method 1

#include <stdio.h>
#include <stdlib.h>

int main()
{

    int number1, number2, number3;

    printf("Enter the first number : ");
    scanf("%d", & number1);

    printf("Enter the second number : ");
    scanf("%d", & number2);

    printf("Enter the third number : ");
    scanf("%d", & number3);


    if(number 1 > number 2 && number 1 > number 3){
        printf("\n%d is the largest number you entered", number 1);
    }
    else
    if(number2 > number1 && number2 > number3){
        printf("\n%d is the largest number you entered", number2);
    }
    else
    if(number3 > number1 && number3 > number2){
        printf("\n%d is the largest number you entered", number3);
    }
    else printf("All numbers you entered are equal.\n");

    return 0;
}

Largest Number.
All three numbers are the same.

Method 2

#include <stdio.h>
#include <stdlib.h>

int main()
{

    int number1, number2, number3 ;

    printf("Enter the first number : ");
    scanf("%d", & number1);

    printf("Enter the second number : ");
    scanf("%d", & number2);

    printf("Enter the third number : ");
    scanf("%d", & number3);

    if((number1 == number2 ) && (number1 == number3))
        printf("\nAll numbers you entered are equal.\n");
    else{
    int largest = number1;
    if(number2 > largest) largest = number2;
    if(number3 > largest) largest = number3;

    printf("\n%d is the largest number you entered", largest);
    }
    return 0;
}

Related Articles

How to reverse an Array in C

How to Calculate Power of a Number Using C++

Functional Programming in C++

Asha Shoukeir

About Asha shoukeir

Software Developer and System Administrator

View all posts by Asha shoukeir →

Leave a Reply