C Program to find the biggest of three numbers using simple if statement
In this program we are finding the largest of 3 numbers using simple if statement. Here we are going to take any 3 numbers as input and display the largest among them.
Description:
Program takes any 3 integer or float or double numbers and prints the greatest number.
a, b and c are three input numbers.
Algorithm to calculate biggest of 3 numbers:
STEP 1: START
STEP 2: READ three numbers
READ a, b, c
STEP 3: COMPARE a with b and c
if a >= b and a >= c
PRINT “a is Biggest”
STEP 4: COMPARE b with a and c
if b >= a and b >= c
PRINT “b is Biggest”
STEP 5: COMPARE c with a and b
if c >= a and c >= b
PRINT “c is Biggest”
STEP 7: END
Program to find biggest of three numbers:
#include <stdio.h>
#include<conio.h>
int main() {
double a,b,c;
printf("Enter three numbers: ");
scanf("%lf %lf %lf", &a, &b, &c);
// if a is greater than both b and c, a is the largest
if (a >= b && a >= c)
printf("%f is the biggest number.", a);
// if b is greater than both a and c, b is the largest
if (b >= a && b >= c)
printf("%f is the biggest number.", b);
// if c is greater than both a and b, c is the largest
if (c >= a && c >= b)
printf("%f is the biggest number.", c);
getch();
return 0;
}
Output:
Enter three numbers: 7.2 12 23.5
23.500000 is the biggest number.
Additional information:
Syntax of simple if statement:
if(condition)
statements
Simple if statement is a decision making statement. If the condition is true, the statements inside the if block are executed. If the condition is false, the statements inside the if block are skipped and execution continues with next statement.
Different if statements:
simple if statement
if else statement
nested if else statement
else if ladder statement
Examples:
if(age >= 18)
printf(“You can vote”);
if(percentage >= 70)
printf(“Student result is First Class with Distinction”);