使用 if 语句
C
xxxxxxxxxx
int main() {
double n1, n2, n3;
printf("Enter three different numbers: ");
scanf("%lf %lf %lf", &n1, &n2, &n3);
if (n1 >= n2 && n1 >= n3)
printf("%.2f is the largest number.", n1);
if (n2 >= n1 && n2 >= n3)
printf("%.2f is the largest number.", n2);
if (n3 >= n1 && n3 >= n2)
printf("%.2f is the largest number.", n3);
return 0;
}
使用 if...else 阶梯
C
xxxxxxxxxx
int main() {
double n1, n2, n3;
printf("Enter three numbers: ");
scanf("%lf %lf %lf", &n1, &n2, &n3);
if (n1 >= n2 && n1 >= n3)
printf("%.2lf is the largest number.", n1);
else if (n2 >= n1 && n2 >= n3)
printf("%.2lf is the largest number.", n2);
else
printf("%.2lf is the largest number.", n3);
return 0;
}
使用嵌套 if...else
C
xxxxxxxxxx
int main() {
double n1, n2, n3;
printf("Enter three numbers: ");
scanf("%lf %lf %lf", &n1, &n2, &n3);
if (n1 >= n2) {
if (n1 >= n3)
printf("%.2lf is the largest number.", n1);
else
printf("%.2lf is the largest number.", n3);
} else {
if (n2 >= n3)
printf("%.2lf is the largest number.", n2);
else
printf("%.2lf is the largest number.", n3);
}
return 0;
}
Enter three numbers: -4.5 3.9 5.6 5.60 is the largest number.
Linux - 如何安装 anc-api-tools
Linux - 如何安装 curvedns
Linux - 如何安装 zenmap
Python - 检查数字是正数、负数还是 0
C - 计算整数中的位数
C++ - 检查一个数字是否是素数
C++ - 检查闰年
C - 使用动态内存分配查找最大数
Kotlin - 反转数字
JavaScript - 检查字符串是否以某些字符开头和结尾
Linux - 如何安装 zstd
Linux - 如何安装 xbitmaps
C++ - 求商和余数
Kotlin - 将数字四舍五入到 n 个小数位
Python - 编写 Excel (XLSX) 文件
Java - 反转数字
Kotlin - 查找数字的阶乘
Java - 创建金字塔和图案
We have been online since 2021 and 1 millions of people around the globe have visited our website since then
More visitors every month