Posted in: E Learn

Program: Find Largest Number among three inputs | C

Explanation:

  1. Header File Inclusion: The #include <stdio.h> line includes the standard input-output library necessary for using printf and scanf functions.
  2. Main Function: The int main() is the starting point of the program.
  3. Variable Declaration: Three integer variables num1, num2, and num3 are declared to store the user inputs.
  4. User Input:
    • The program prompts the user to enter three different numbers.
    • scanf("%d", &num1); reads the first integer from the user and stores it in num1.
    • scanf("%d", &num2); reads the second integer from the user and stores it in num2.
    • scanf("%d", &num3); reads the third integer from the user and stores it in num3.
  5. Conditional Statements:
    • The program uses nested if statements to compare the three numbers and determine the largest.
    • The outer if checks if num1 is greater than num2.
    • If true, an inner if checks if num1 is also greater than num3 to determine if num1 is the largest.
    • If num1 is not greater than num3, then num3 is the largest.
    • If the outer if is false, another inner if checks if num2 is greater than num3 to determine if num2 is the largest.
    • If num2 is not greater than num3, then num3 is the largest.
  6. Print the Largest Number: The printf function prints the largest number.
  7. Return Statement: The return 0; indicates that the program ended successfully.

When you run this program, it will prompt you to enter three numbers and then display the largest of the three.

See also  Photoshop- Basket Effect

Leave a Reply

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

Back to Top