Find the Largest Number Using Nested if-else Statement
Unlike the previous method, we consider only one condition in each if statement and put the remaining condition inside it as a nested if-else statement.
C Program to Find the Largest Number Using if-else Statement
C
// C program to find the largest number among three number // using nested if-else #include <stdio.h> int main() { int A, B, C; printf ( "Enter three numbers: " ); 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; } |
Output
Enter three numbers: 32764 is the largest number.
Complexity Analysis
- Time complexity: O(1) as it is doing constant operations
- Auxiliary space: O(1)
C program to Find the Largest Number Among Three Numbers
Here, we will learn how to find the largest number among the three numbers using the C program. For example, the largest number among 2, 8, and 1 is 8.