1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
/*不交换中间变量交换两个数*/
#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;
}
|