我是靠谱客的博主 机灵苗条,这篇文章主要介绍C语言 宏定义练习:交换数据,现在分享给大家,希望可以做个参考。

题目描述

请补充“#define SWAP(a,b) …”,其功能是交换a与b的数据。

#include <stdio.h>
/******************************************/
/// Write your code here,
/// beginning with “#define”…

/******************************************/
int main()
{
int a, b;
while(~scanf("%d%d", &a, &b))
{
if(a < 5) {
SWAP(a, b);
} else {
a = b;
}
printf("%d %dn", a, b);
}
SWAP(a, a);
printf("%d %dn", a, a);
return 0;
}

样例输入 Copy

0 1
1 0

样例输出 Copy

1 0
0 1
0 0

代码

#include <stdio.h>
/******************************************/
/// Write your code here,
///
beginning with "#define"...
#define SWAP(a,b) {a=b-a;b=b-a;a=a+b;}
/******************************************/
int main()
{
double a, b;
while(~scanf("%lf%lf", &a, &b))
{
if(a < 5.0)
{
SWAP(a, b);
}
else
{
a = b;
}
printf("%.0f %.0fn", a, b);
}
//SWAP(a, a);
printf("%.0f %.0fn", a, a);
return 0;
}

最后

以上就是机灵苗条最近收集整理的关于C语言 宏定义练习:交换数据的全部内容,更多相关C语言内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(100)

评论列表共有 0 条评论

立即
投稿
返回
顶部