作业8 Problem G: 编写函数:Swap (I) (Append Code)
来源:互联网 发布:出国留学值得吗 知乎 编辑:程序博客网 时间:2024/05/21 01:43
Description
编写用来交换两个数的函数,使得“Append Code”中的main()函数能正确运行。
-----------------------------------------------------------------------------
用C实现三个函数int_swap()、dbl_swap()、SWAP(),其中SWAP()是个带参宏。
用C++实现两个函数,都以swap()命名。
以上函数的调用格式见“Append Code”。这里不给出函数原型,它们的参数请通过main()函数自行确定。
Input
输入为4行,每行2个数。
Output
输出为4行,每行2个数。每行输出的两数为每行输入的逆序。
Sample Input
12 57
9 -3
-12 4
3 5
Sample Output
57 12
-3 9
4 -12
5 3
HINT
“Append Code”中用到的头文件、全局变量或宏的定义应自行补充。
Append Code
append.c, append.cc,
&&
#include<stdio.h>#define SWAP(t, x, y){t = x;x = y;y = t;}/*定义swap应在一行内*/int int_swap(int *x, int *y){ int num; num = *x; *x = *y; *y = num;}int dbl_swap(double *x, double *y){ double num; num = *x; *x = *y; *y = num; }int main(){ int x1, y1, t1; double x2, y2, t2; scanf("%d %d", &x1, &y1); int_swap(&x1, &y1); printf("%d %d\n", x1, y1); scanf("%d %d", &x1, &y1); SWAP(t1, x1, y1); printf("%d %d\n", x1, y1); scanf("%lf %lf", &x2, &y2); dbl_swap(&x2, &y2); printf("%lg %lg\n", x2, y2); scanf("%lf %lf", &x2, &y2); SWAP(t2, x2, y2); printf("%lg %lg\n", x2, y2);}
0 0
- 作业8 Problem G: 编写函数:Swap (I) (Append Code)
- Problem E: 编写函数:Swap (I) (Append Code)
- Problem E: 编写函数:Swap (I) (Append Code)
- 编写函数:Swap (I) (Append Code)
- Problem E: 编写函数:递归求逆序 (Append Code)
- Problem C: 编写函数:矩阵乘法 (Append Code)
- 作业8 问题 A: 编写函数:比较字符串 之一 (Append Code)
- Problem D: 编写函数:String to Integer (IV) (Append Code) && 2/8/16进制到10进制的转换
- 实验9 Problem C: 编写函数:字符串的复制 之一 (Append Code)
- Problem A: 编写函数:三个数的最大最小值 (Append Code)
- Problem A: 编写函数:三个数的最大最小值 (Append Code)
- 编写函数:日期的顺序 (Append Code)
- 山科大oj--编写函数:各位数字之和 (Append Code)
- 山科大oj--编写函数:各位数字之和 (Append Code)
- 编写函数:三个数的最大最小值 (Append Code)
- swap 函数的编写
- 山科大 oj 编写函数:清除字符串首尾的空白符 (Append Code)
- 实验9 问题 A: 编写函数:三个数的最大最小值 (Append Code)
- Ubuntu 16.04 LTS 一直不可更新,已可使用三种升级方法解析(一定有适合的方法)
- Error:Connection timed out: connect. If you are behind an HTTP proxy, please configure the proxy set
- cocos2dx EventListenerCustom 和NotificationCenter的优缺点
- 简单算法
- re命名捕获
- 作业8 Problem G: 编写函数:Swap (I) (Append Code)
- 程序员的书籍资源
- vi编辑器的配置
- 离线web缓存
- Android Studio Error running app IDE or the Gradle plugin to the latest version
- hdu1099(map用法)
- 计算机视觉与图像处理(一)——卷积与opencv
- 121 122 123 188 Best Time to Buy and Sell Stock
- Elasticsearch 简介