欢迎光临
我们一直在努力

比较3个数的大小c语言,如何用c语言比较三个数大小

目标:

多种方法实现3个数的大小比较

代码: int compare01(int a, int b, int c){ //最原始的if条件判断 if( a > b){if( a > c){return a;}else{return c;}}else{if( 美国高防vps b > c){return b;}else return c;}}int compare02(int a, int b, int c){ // 三目运算符,略沙雕 return (a > b ? a : b) > c ? (a > b ? a : b) : c;}int compare03( int a, int b, int c){//int max = a;// 一开始就假设 a 是最大的值 if( max < b)max = b; if( max < c)max = c;return max;} int main(){int a = 1, b = 222, c = 13;int max;max = compare01(a,b,c);printf(“max = %d\n”,max);max = compare02(a,b,c);printf(“max = %d\n”,max);max = compare03(a,b,c);printf(“max = %d\n”,max);} 效果: 80436764

赞(0)
【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。