C++题目,求高手帮忙!谢谢了!
来源:百度知道 编辑:UC知道 时间:2024/09/21 20:15:59
C++中如何设置一个程序,题目:有a和b两变量,a=c,b=d,c和d为常数,设置一程序将a和b的值对换!即使b=c,a=d!
#include <iostream>
#include<conio.h>
using namespace std;
int main( void )
{
int a,b;
cout<<"input a,b: "<<endl;
cin>>a>>b;
a=a+b;
b=a-b;
a=a-b;
cout<<"a = "<<a<<", b = "<<b<<endl;
getch();
return 1;
}
k=a;
a=b;
b=k;
int k;
k=a;
a=b;
b=k;