C 语言实例 – 判断三个数中的最大数

C语言教程评论

C 语言实例 - 判断三个数中的最大数

通过屏幕我们输入三个数字,并找出最大的数。

#include <stdio.h>

int main()
{
    double n1, n2, n3;

    printf("请输入三个数,以空格分隔: ");
    scanf("%lf %lf %lf", &n1, &n2, &n3);

    if( n1>=n2 && n1>=n3 )
        printf("%.2f 是最大数。", n1);

    if( n2>=n1 && n2>=n3 )
        printf("%.2f 是最大数。", n2);

    if( n3>=n1 && n3>=n2 )
        printf("%.2f 是最大数。", n3);

    return 0;
}

运行结果:文章源自公式库网-https://www.gongshiku.com/html/202112/c-yuyanshili-panduansangeshuzhongdezuidashu.html

请输入三个数,以空格分隔: 1 2 3
3.00 是最大数。
文章源自公式库网-https://www.gongshiku.com/html/202112/c-yuyanshili-panduansangeshuzhongdezuidashu.html文章源自公式库网-https://www.gongshiku.com/html/202112/c-yuyanshili-panduansangeshuzhongdezuidashu.html
运营不易,
感谢支持!
weinxin
我的微信
我的微信公众号
我的微信公众号扫一扫
weinxin
我的公众号
 最后更新:2021-12-7
公式库网
  • 本文由 公式库网 发表于 2021年12月4日22:20:52
  • 转载请务必保留本文链接:https://www.gongshiku.com/html/202112/c-yuyanshili-panduansangeshuzhongdezuidashu.html

发表评论