面向对象程序设计上机练习四(变量引用)
Time Limit: 1000MS
Memory Limit: 65536KB
Problem Description
将变量的引用作为函数形参,实现2个int型数据交换。
Input
输入2个int型整数。
Output
输出2个整数交换前后的值。
Example Input
88 66
Example Output
88 66 66 88
#include<iostream>
using namespace std ;
void f(int &a , int &b)
{
int temp ;
temp = a ;
a = b ;
b = temp ;
}
int main()
{
int x , y ;
cin>>x>>y ;
cout << x <<" "<< y << endl ;
f(x,y) ;
cout << x << " "<<y << endl ;
return 0 ;
}
#include<iostream>
using namespace std ;
void f(int &a , int &b)
{
int temp ;
temp = a ;
a = b ;
b = temp ;
}
int main()
{
int x , y ;
cin>>x>>y ;
cout << x <<" "<< y << endl ;
f(x,y) ;
cout << x << " "<<y << endl ;
return 0 ;
}