
C Program to find the largest among three numbers
Algorithm
Input: Input three numbers
output: Finds and displays the largest among the three input numbers
- Start
- Input three numbers say a, b, c
- if a>b and b>c
3.1 Print 'a' is greater - else if
4.1 b>a and b>c
4.2 Print 'b' is greater - else
5.1 Print 'c' is greater - Stop
C Program
#include <stdio.h>
int main( )
{
int a, b, c;
printf("Enter first number: ");
scanf("%d", &a);
printf("Enter second number: ");
scanf("%d", &b);
printf("Enter third number: ");
scanf("%d", &c);
if (a > b && a > c) {
printf("%d is the largest among %d, %d and %d", a, a, b, c);
}
else if (b > c && b > a) {
printf("%d is the largest among %d, %d and %d", b, a, b, c);
}
else {
printf("%d is the largest among %d, %d and %d", c, a, b, c);
}
return 0;
}
Note: This Program was created using visual studio code. The Program file can be downloaded by clicking here
Comments