74.0k views
0 votes
2.8 Code Practice: Question 1

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

User Zemirco
by
5.3k points

2 Answers

4 votes

Input: A = 2, B = 8, C = 1

Output: Largest number = 8

User Shavanna
by
5.3k points
2 votes

Answer:

The program to this question can be given as:

Program:

#include <stdio.h> //define header file

int main() //define main method.

{

int a1,b1,c1; //define variable

printf("Enter three numbers:\\"); //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

Step-by-step 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.
User Nktoronto
by
5.3k points