/*不交换中间变量交换两个数*/ #include <iostream> using namespace std; void Fun(int&x,int&y) { x=x+y; y=x-y; x=x-y; } int main() { int a=3,b=4; cout<<"交换前"<<endl<<"a="<<a<<"\t"<<"b="<<b<<endl; Fun(a,b); cout<<"交换后"<<endl<<"a="<<a<<"\t"<<"b="<<b<<endl; return 0; }
时间: 2024-09-20 05:39:20