返回

比较三个数的大小

发布时间:2023-05-02 12:05:02 335

1、方法一

2、方法二

3、方法二的优缺点

1、方法一

  • 先比较a和b,将较大值赋值给max
  • 再比较max和c,若c>max,把c赋值给max
  • 最后输出max
#include

#include

int main()

{

int a,b,c,max;

scanf("%d%d%d",&a,&b,&c);

if(a>b)

{

max=a;

}
else

{

max=b;

}

if(max<c)

{

max=c;

}

printf("max=%d\n",max);

return 0;

}

比较三个数的大小_#include

2、方法二

#include

#include

int main()

{

int a,b,c,max;

scanf("%d%d%d",&a,&b,&c);

if(a>=b&&a>=c)

max=a;

if(b>=a&&b>=c)

max=b;

if(c>=a&&c>=b)

max=c;

printf("max=%d\n",max);

return 0;

}

比较三个数的大小_#include_02

3、方法二的优缺点

优点:比较简洁

缺点:如果是在10个数中找出最大值就太麻烦了

特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(0)
按点赞数排序
用户头像
精选文章
thumb 中国研究员首次曝光美国国安局顶级后门—“方程式组织”
thumb 俄乌线上战争,网络攻击弥漫着数字硝烟
thumb 从网络安全角度了解俄罗斯入侵乌克兰的相关事件时间线