Index « Previous Next »

Question

Write a program that prompts the user to input three numbers and outputs the largest number.

Source Code

#include <stdio.h>

int main()
{
    int num1, num2, num3;

    printf("Enter three numbers :");
    scanf("%d%d%d", &num1, &num2, &num3);

    if (num1 > num2 && num1 > num3)
    {
        printf("Largest of three numbers is %d.", num1);
    }
    else if (num2 > num3)
    {
        printf("Largest of three numbers is %d.", num2);
    }
    else
    {
        printf("Largest of three numbers is %d.", num3);
    }

    return 0;
}

Output

Enter three numbers :8 18 11
Largest of three numbers is 18.