#include <stdio.h>

int main() {
    // Variable declaration
    int num1, num2, num3;

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

    // Variable to hold the largest number
    int largest;

    // Determine the largest number
    if (num1 >= num2 && num1 >= num3) {
        largest = num1;  // num1 is the largest
    } else if (num2 >= num1 && num2 >= num3) {
        largest = num2;  // num2 is the largest
    } else {
        largest = num3;  // num3 is the largest
    }

    // Display the result
    printf("The largest number is: %d\n", largest);
    return 0;
}

Explanation

Include the Standard I/O Library:

  • #include <stdio.h>: This line includes the standard input-output library necessary for using printf and scanf functions.

Main Function:

  • int main(): This is the entry point of the program.

Variable Declaration:

  • int num1, num2, num3;: We declare three integer variables to hold the numbers that the user will input.

User Input:

  • printf("Enter three numbers: ");: This line prompts the user to enter three numbers.
  • scanf("%d %d %d", &num1, &num2, &num3);: This reads the three integers from the user and stores them in num1, num2, and num3.

Finding the Largest Number:

  • We declare an integer variable largest to store the largest number.
  • The first if statement checks if num1 is greater than or equal to both num2 and num3. If true, num1 is assigned to largest.
  • The else if checks if num2 is greater than or equal to both num1 and num3. If true, num2 is assigned to largest.
  • If neither of the above conditions is true, num3 is assigned to largest.

Display the Result:

  • printf("The largest number is: %d\n", largest);: This line prints out the largest number.

Return Statement:

  • return 0;: This indicates that the program executed successfully.

OUTPUT

Enter three numbers: 10 20 30

The largest number is: 30

Leave a Reply

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

Verified by MonsterInsights