In this tutorial you will learn about the C Program to find Largest of Three Numbers and its application with practical example.
C Program to Find Largest of Three Numbers
In this tutorial, we will learn to create a C program that will find the Largest of Three Numbers using C programming.
Prerequisites
Before starting with this tutorial we assume that you are the best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
- Conditional statement in C programming.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declaring the variables for the program. 2. Taking the three input numbers. 3. Checking the Largest number from those three. 4. Printing the largest of three numbers. 5. End the program. |
Program to Find Largest of Three Numbers
In c programming, it is possible to take numerical input from the user to find the Largest of Three Numbers. Then we will pass those numbers to the conditional statements to find the largest number. At last, we will print the largest number from the given three numbers.
With the help of this program, we can find the Largest Number Among Three Numbers.
Program code to find the largest of Three Numbers:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
/* ** C Program to find Largest of Three Numbers ** */ #include <stdio.h> int main() { //Declaring the required variables for the program. double no1, no2, no3; //Taking the input numbers from the user printf("Enter three different numbers: "); scanf("%lf %lf %lf", &no1, &no2, &no3); //checking the largest number // if no1 is greater than both no2 and no3, no1 is the largest //Printing The output number if (no1 >= no2 && no1 >= no3) printf("%.2f is the largest number.", no1); // if no2 is greater than both no1 and no3, no2 is the largest //Printing THe output number if (no2 >= no1 && no2 >= no3) printf("%.2f is the largest number.", no2); // if no3 is greater than both no1 and no2, no3 is the largest if (no3 >= no1 && no3 >= no2) //Printing The output number printf("%.2f is the largest number.", no3); return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- no1 = it will hold the integer value.
- no2 = it will hold the integer value.
- no3 = it will hold the integer value.
Input numbers for the program.
Program Logic Code.
Printing output for the greatest number.