交换 x,y;
NO.1:
swap函数:
#include <bits/stdc++.h>
using namespace std;
int main() {
float x,y;
cin>>x>>y;
swap(x,y);
cout << x <<endl<<y<<endl;
return 0;
}
NO.2:
3个变量:
#include<iostream>
using namespace std;
int main()
{
float a,b,c;
cin>>a>>b;
c=a;a=b;b=c;
cout<<a<<b;
}
NO.3:
“和 - 盒”法:
#include <bits/stdc++.h>
using namespace std;
int main() {
float x,y;
cin>>x>>y;
x=x+y;
y=x-y;
x=x-y;
cout << x <<endl<<y<<endl;
return 0;
}