用宏定义,不用?:和比较switch等求两个数中较大的数
2014-08-04 19:23
351 查看
#include<stdio.h>
#include<math.h>
#define MAX(A,B) (A+B+abs(A-B))/2
int main()
{
int a=7,b=10,max;
printf("a=%d b=%d\n",a,b);
max=MAX(a,b);
printf("max=%d\n",max);
return 0;
}
输出结果
a=7 b=10
max=10
Press any key to continue
#include<stdio.h>
int main()
{
int i=1,j=1,m=1,n=1,a=1,b=1;
if((m=(a>b))&&(n=(a>b)));
printf("m=%d n=%d ",m,n);
printf("(n++)=%d ",n++);
printf("n=%d ",n);
m=(a+b+a,n++) ;
printf("m=%d ",m);
i+=j+=3;
printf("i=%d ",i);
return 0;
}
输出结果
m=0 n=1 (n++)=1 n=2 m=2 i=5 Press any key to continue
#include<math.h>
#define MAX(A,B) (A+B+abs(A-B))/2
int main()
{
int a=7,b=10,max;
printf("a=%d b=%d\n",a,b);
max=MAX(a,b);
printf("max=%d\n",max);
return 0;
}
输出结果
a=7 b=10
max=10
Press any key to continue
#include<stdio.h>
int main()
{
int i=1,j=1,m=1,n=1,a=1,b=1;
if((m=(a>b))&&(n=(a>b)));
printf("m=%d n=%d ",m,n);
printf("(n++)=%d ",n++);
printf("n=%d ",n);
m=(a+b+a,n++) ;
printf("m=%d ",m);
i+=j+=3;
printf("i=%d ",i);
return 0;
}
输出结果
m=0 n=1 (n++)=1 n=2 m=2 i=5 Press any key to continue
相关文章推荐
- 两个变量a,b,不用“if”,“? :”,switch或者其它判断语句,找出两个数中间比较大的
- 编写函数求两个整数 a 和 b 之间的较大值。要求不能使用if, while, switch, for, ?: 以及任何的比较语句
- 有两个变量a和b,不用“if”、“? :”、“switch”或其他判断语句,找出两个数中比较大的
- 不用任何比较判断找出两个数中较大的数。
- 不用”if“,”?:“,”switch“或其他判断语句,求两个数中较大的数或较小的数
- 有两个变量a 和 b,不用if、?: 、switch 或者其他判断语句,找出两个数中比较大的那个
- 不用任何比较判断找出两个数中较大的数
- 有两个变量a 和 b,不用if、?: 、switch 或者其他判断语句,找出两个数中比较大的那个
- 不用任何比较判断找出两个数中较大的
- 编写函数求两个整数 a 和 b 之间的较大值。要求不能使用if, while, switch, for, ?: 以及任何的比较语句
- 不用if ,switch ? :比较两个整型数
- 【面试题】不用if,条件表达式,switch等判断语句------找出两个数中较大的
- 不用任何比较判断找出两个数中较大的数
- 今天学习时突然联想到这样一个有趣但无用的问题:利用C语言(不能是其他语言)求两个整数的较大/小值-----要求不用if、三目?、switch、循环、数组、加减乘除求余、位运算符以及任何库函数
- 选出两个数中较大者,不用if, ? : ,switch等判断语句.
- Moderate 不用比较符返回较大的数 @CareerCup
- C语言笔试题精选1---求两个数之间较大的数,不使用if、while、switch、for、?:/以及任何比较语句
- 使用C语言编写程序,求两个整数的较大值(随机输入两个数,比较大小)
- 用Groovy实现判断两个int数值大小(不用比较运算符,考虑溢出)
- CI19.4-不用条件语句和比较操作符求两个数的较大值