-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab11.5.cpp
41 lines (35 loc) · 836 Bytes
/
lab11.5.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include<iostream>
using namespace std;
void swap(int &a, int &b)
{
a=a+b;
b=a-b;
a=a-b;
}
void swap(float &a, float &b)
{
a=a+b;
b=a-b;
a=a-b;
}
void swap(char &a, char &b)
{
char t=a;
a=b;
b=t;
}
int main()
{
int x1=12,y1=20;
float x2=10.1,y2=13.6;
char x3='A',y3='B';
cout <<"before swap int a="<<x1<<",int b="<<y1<<endl;
cout <<"before swap float a="<<x2<<",float b="<<y2<<endl;
cout <<"before swap char a="<<x3<<",char b="<<y3<<endl;
swap(x1,y1);
swap(x2,y2);
swap(x3,y3);
cout <<"after swap int a="<<x1<<",int b="<<y1<<endl;
cout <<"after swap float a="<<x2<<",float b="<<y2<<endl;
cout <<"after swap char a="<<x3<<",char b="<<y3<<endl;
}