In this program user is asked to enter three
numbers and this program will find the largest number among three numbers entered
by user. This program can be solved in more than one way.
Method 1:
#include <stdio.h>
int main(){
float
a, b, c;
printf("Enter three numbers:\n");
scanf("%f %f %f", &a, &b, &c);
if(a>=b && a>=c)
printf("\nLargest number = %.2f", a);
if(b>=a && b>=c)
printf("\nLargest number = %.2f", b);
if(c>=a && c>=b)
printf("\nLargest number = %.2f", c);
return 0;
}
Method 2:
#include <stdio.h>
int main(){
float
a, b, c;
printf("Enter three numbers:\n");
scanf("%f
%f %f", &a, &b, &c);
if (a>=b) {
if(a>=c)
printf("\nLargest number = %.2f",a);
else
printf("\nLargest number = %.2f",c);
}
else {
if(b>=c)
printf("\nLargest number = %.2f",b);
else
printf("\nLargest number = %.2f",c);
}
return 0;
}
Method 3:
#include <stdio.h>
int main(){
float
a, b, c;
printf("Enter three numbers:\n");
scanf("%f %f %f", &a, &b, &c);
if(a>=b && a>=c)
printf("\nLargest number = %.2f", a);
else if(b>=a && b>=c)
printf("\nLargest number = %.2f", b);
else
printf("\nLargest number = %.2f", c);
return 0;
}