Ask Question
12 November, 10:51

2.8 Code Practice: Question 1

Write a program that takes three numbers as input and prints the largest.

+2
Answers (2)
  1. 12 November, 10:55
    0
    Input: A = 2, B = 8, C = 1

    Output: Largest number = 8
  2. 12 November, 10:56
    0
    The program to this question can be given as:

    Program:

    #include / /define header file

    int main () / /define main method.

    {

    int a1, b1, c1; / /define variable

    printf ("Enter three numbers:/n"); / /message

    scanf ("%d",&a1); / /input numbers.

    scanf ("%d",&b1); //input numbers.

    scanf ("%d",&c1); //input numbers.

    if (a1>b1) / /check condition

    {

    //check condition

    if (a1>c1) / /inner if block

    {

    printf ("The largest number: %d", a1); / /message

    }

    else / /inner else block

    {

    printf ("The largest number: %d", c1); //message

    }

    }

    else / /else block

    {

    //check condition

    if (b1>c1) / /inner if block.

    {

    printf ("The largest number: %d", b1); //message

    }

    else / /else block

    {

    printf ("The largest number: %d", c1); //message

    }

    }

    return 0; / /return 0.

    }

    Output:

    Enter three numbers:

    22

    44

    11

    The largest number: 44

    Explanation:

    The description of the above program can be given as:

    In the C language program firstly we define the header file. Then we define the main function. In the main function, we define three variables that are "a1, b1 and c1". In this variable, we take input from the user. Then we define the conditional statements. In the if block we check if the value of a1 is greater then the value of b1 if this condition is true so we use another condition that if the value of a1 is greater then the value of c1. so, it will print the largest value. If the above condition is not true then it will go to else section. In the else part we check the condition that if the value of b1 is greater then the value of c1. if it is true it will print the largest number value.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “2.8 Code Practice: Question 1 Write a program that takes three numbers as input and prints the largest. ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers