标签:交换
#include <stdio.h> #include<stdlib.h> void swap(int *pa, int *pb) { int tmp = *pa; *pa = *pb; *pb= tmp; } int main() { int n1 = 0; int n2 = 0; char *p1 = &n1; char *p2 = &n2; printf("请输入两个数:"); scanf_s("%d%d", &n1, &n2); swap(p1,p2); printf("n1=%d n2=%d\n", n1, n2); system("pause"); return 0; }
运行结果:
请输入两个数:45 12
12 45
请按任意键继续. . .
使用函数实现两个数的交换
本文出自 “10910765” 博客,请务必保留此出处http://10920765.blog.51cto.com/10910765/1725440
标签:交换
原文地址:http://10920765.blog.51cto.com/10910765/1725440