C Language Example - Determining the Maximum of Three Numbers
We input three numbers via the screen and find the largest one.
Example
#include <stdio.h>
int main()
{
double n1, n2, n3;
printf("Please enter three numbers separated by spaces:");
scanf("%lf %lf %lf", &n1, &n2, &n3);
if( n1>=n2 && n1>=n3 )
printf("%.2f is the maximum number.", n1);
if( n2>=n1 && n2>=n3 )
printf("%.2f is the maximum number.", n2);
if( n3>=n1 && n3>=n2 )
printf("%.2f is the maximum number.", n3);
return 0;
}
Run result:
请输入三个数,以空格分隔: 1 2 3 3.00 是最大数。other extensions
C Language Examples