不用if、switch、?: 实现a、b比较大小
int max = (a + b + abs(a - b)) / 2;
分析:
if a > b, max = (a + b + a - b) / 2 = a
if b > a, max = (a + b + b - a) / 2 = b
mb6304a73bed12a 博主文章分类:基础知识 ©著作权
int max = (a + b + abs(a - b)) / 2;
分析:
if a > b, max = (a + b + a - b) / 2 = a
if b > a, max = (a + b + b - a) / 2 = b
上一篇:switch语句的输出问题
下一篇:蛇形矩阵
1 判断语句(四)、switch语句C++提供了一种用于多分支选择的switch语句。当if语句较多时,容易出现混乱,可读性差,这时我们就选择使用switch语句。switch语句一般形式如下:switch(表达式){ case 常量表达式1; 语句1; break; case 常量表达式2; 语句2; break; ... cas
java基础(三):条件判断,循环,类与对象
举报文章
请选择举报类型
补充说明
0/200
上传截图
格式支持JPEG/PNG/JPG,图片不超过1.9M