Overview:
In this example, you'll learn to find the largest number among three numbers using if else statements. First of all, in this article, I will define numbers and then demonstrate the logic to find the largest number among the three. Moreover, I will write a logic and C program to find the largest number amongst the three numbers with output. At last, I will explain the execution of this program.
Table of contents:
- What is the number?
- Demonstration how to find the largest number among three numbers
- Logic to find the largest number among three numbers
- C program to find the largest number among three numbers with output
- Conclusion
What is a number?
A number is an object that uses digits to perform mathematical tasks. Calculus, which is a branch of mathematics, includes many numbers such as integers, whole numbers, real numbers, and imaginary numbers. Here, I will discuss numbers to perform arithmetic addition operations. Moreover, numbers are a combination of digits, some symbols, and decimal points. For instance, 127.23 is a rational number. There are many numbers such as whole numbers, natural numbers(positive integers), negative integers, rational numbers, etc.
Demonstration how to find the largest number among three numbers
Logic to find the largest number among three numbers
- Step 1:Read the three numbers to be compared, as A, B and C.
- Step 2:Check if A is greater than B.
- Step 3:If true, then check if A is greater than C.
- Step 4:If true, print 'A' as the greatest number.
- Step 5:If false, print 'C' as the greatest number.
- Step 6:If false, then check if B is greater than C.
- Step 7:If true, print 'B' as the greatest number.
- Step 8:If false, print 'C' as the greatest number.
C program to find the largest number among three numbers with output
#include <stdio.h> int main() { int A, B, C; printf("Enter three numbers: \n"); scanf("%d %d %d", &A, &B, &C); if (A >= B) { if (A >= C) printf("%d is the largest number.", A); else printf("%d is the largest number.", C); } else { if (B >= C) printf("%d is the largest number.", B); else printf("%d is the largest number.", C); } return 0; }
The output of the Program: Enter the numbers: 8 45 1 45 is the largest number.
Conclusion:
In this program, three numbers are assigned to the three variables one by one. Then, compare the two selected of them with the use of a comparison operator. Repeat the same process for the other two. After the successful execution of the program, the final largest number of the three is displayed on the screen.