Program to Find the Largest of Three Numbers

Problem Statement: Write a C program to find the largest of three numbers.

Description:
This program compares three numbers using a series of if-else conditions to determine which number is the largest. It showcases how to use logical conditions to compare values.

Usage:
The user enters three integers, and the program outputs the largest number among them.

Code:

C
#include <stdio.h>

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

    // Asking user to input three integers
    printf("Enter three numbers: ");
    scanf("%d %d %d", &num1, &num2, &num3);

    // Comparing the three numbers
    if (num1 >= num2 && num1 >= num3) {
        printf("Largest number is: %d\n", num1);
    } else if (num2 >= num1 && num2 >= num3) {
        printf("Largest number is: %d\n", num2);
    } else {
        printf("Largest number is: %d\n", num3);
    }

    return 0;
}

Explanation:

  • The program checks which of the three numbers is the largest using conditional statements.
  • if-else statements compare the values of num1, num2, and num3 to determine the largest.

Test here:

Leave a Reply

Your email address will not be published. Required fields are marked *