2769 交换两个变量的值

risnotl / 2024-11-12 / 原文

#include<iostream>
using namespace std;

int main() {
	//输入两个整数,保存在两个变量a和b中 
	int a,b;
	cin>>a>>b;
	
	//交换两个变量的值需要借助一个临时变量作为中介
	int t = a;	 	//先把a记录出来 
	a=b;			//把b的值放在b中 
	b=t; 			//把临时变量中原本的a的值放入b中
	
	//输出交换后的结果 
	cout<<a<<" "<<b; 
	 
	 
	return 0;
}