C++语言实现两个数的交换
1.运行程序,输入参数,结果如下。
输入两个数2和4,交换后为4和2。
2.部分源代码
#include<iostream>
using namespace std;
void main()
{
int n1,n2,temp;
cout<<"输入第一个数:";
cin>>n1;
cout<<"输入第二个数:";
cin>>n2;
cout<<"交换前:"<<endl;
cout<<"第一个数为:"<<n1<<endl;
cout<<"第二个数为:"<<n2<<endl;
******
cout<<"交换后:"<<endl;
cout<<"第一个数为:"<<n1<<endl;
cout<<"第二个数为:"<<n2<<endl;
}