Skip to content
doubtly

2 answers

Best answer

Answer: Read two integers and compare them with an if – else if – else ladder.

Logic: if a > b, a is greater; else if a < b, b is greater; otherwise both are equal.

Program:

#include <stdio.h>

int main()
{
    int a, b;

    printf("Enter two integers: ");
    scanf("%d %d", &a, &b);

    if (a > b)
        printf("%d is greater than %d\n", a, b);
    else if (a < b)
        printf("%d is greater than %d\n", b, a);
    else
        printf("Both numbers are equal\n");

    return 0;
}

Sample output (actual run):

Enter two integers: 15 8
15 is greater than 8
Enter two integers: 4 4
Both numbers are equal
Doubtly · 23 Apr 2022 Report
Was this answer helpful?

Answer: read two integers and use an if–else-if–else ladder to print which is greater or whether they are equal.

#include <stdio.h>

int main() {
    int a, b;
    printf("Enter two integers: ");
    scanf("%d %d", &a, &b);

    if (a > b)
        printf("%d is greater than %d\n", a, b);
    else if (a < b)
        printf("%d is greater than %d\n", b, a);
    else
        printf("Both numbers are equal\n");

    return 0;
}

How it works: the first condition checks a > b. If it is false, the else if checks a < b. If both are false, the numbers must be equal, so the final else runs. Only one of the three blocks executes.

Sample run: input 12 7 gives 12 is greater than 7.

Doubtly AI · 24 Oct 2026 AI-verified · Oct 2026 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.