题目
在主程序通过键盘输入两个正整数,编写并调用自定义函数void swap(int *x,int *y)实现两个整数变量值的交换并输出交换后的结果。
代码
#include <stdio.h>
void swap(int *x, int *y);
int main(void)
{
int a = 0, b = 0;
printf("Please enter a number A:");
scanf("%d", &a);
printf("Please enter a number B:");
scanf("%d", &b);
int *x = &a;
int *y = &b;
swap(x,y);
printf("After exchange,A=%d,B=%d\n", a, b);
return 0;
}
void swap(int *x, int *y)
{
int temp = *x;
*x = *y;
*y = temp;
}
标签:int,void,交换,C语言,swap,printf,习题,指针
From: https://www.cnblogs.com/CoronaZero/p/16835725.html