C Online Compiler
Example: Find Largest Among Three (if-else if-else) in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Find Largest Among Three (if-else if-else) #include <stdio.h> int main() { int num1, num2, num3; // Step 1: Prompt user for input printf("Enter three numbers: "); // Step 2: Read the three numbers from user scanf("%d %d %d", &num1, &num2, &num3); // Step 3: Use if-else if-else ladder to find the largest if (num1 >= num2 && num1 >= num3) { printf("%d is the largest number.\n", num1); } else if (num2 >= num1 && num2 >= num3) { printf("%d is the largest number.\n", num2); } else { printf("%d is the largest number.\n", num3); } return 0; }
Output
Clear
ADVERTISEMENTS