您的位置:首页 > 其它

用宏定义,不用?:和比较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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐