Index « Previous Next »

Question

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

Source Code

#include <stdio.h>

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

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

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

    return 0;
}

Output

Enter three integers :8 18 11
Largest number is 18.