Index « Previous Next »

Question

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

Source Code

#include <stdio.h>

int main()
{
    int num1, num2;

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

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

    return 0;
}

Output

Enter two integers :25 19
Largest number is 25.