Find the Largest Number Using Temporary Variable
In this method, we assume one of the numbers as maximum and assign it to a temporary variable. We then compare this temporary variable with the other two numbers one by one and if the max is smaller than the compared number, we assign the compared number to the max.
C Program to Find the Largest Number Among Three Using Temporary Variable
C
// C Program to Find the Largest Number Among Three using // Temporary Variable #include <stdio.h> int main() { int a = 10, b = 25, c = 3; // temporary varaible int max = a; if (max < b) max = b; if (max < c) max = c; printf ( "Maximum among %d, %d, and %d is: %d" , a, b, c, max); return 0; } |
Output
Maximum among 10, 25, and 3 is: 25
Complexity Analysis
- Time complexity: O(1) as it is doing constant operations
- Auxiliary space: O(1)
Related Articles
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.