Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream.h>
- void swap(int *,int *);
- void swap(float *,float *);
- void swap(char *,char *);
- int main()
- {
- int a,b,c;
- float x,y;
- char p,q;
- cout<<"enter a choice\n";
- cout<<"1.To swap two integers\n";
- cout<<"2.To swap of two floats\n";
- cout<<"3.To swap of two characters\n";
- cin>>a;
- switch(a)
- {
- case 1:
- cout<<"enter two inegers:\n";
- cin>>b>>c;
- cout<<"value before swapping b= "<<b<<" c= "<<c<<endl;
- swap(&b,&c);
- cout<<"value after swapping b= "<<b<<" c= "<<c<<endl;
- break;
- case 2:
- cout<<"enter two floating point numbers:\n";
- cin>>x>>y;
- cout<<"value before swapping x= "<<x<<" y= "<<y<<endl;
- swap(&x,&y);
- cout<<"value after swapping x= "<<x<<" y= "<<y<<endl;
- break;
- case 3:
- cout<<"enter two characters:\n";
- cin>>p>>q;
- cout<<"value before swapping p= "<<p<<" q= "<<q<<endl;
- swap(&p,&q);
- cout<<"value after swapping p= "<<p<<" q= "<<q<<endl;
- break;
- default:
- cout<<"invalod operator\n";
- break;
- }
- return 0;
- }
- 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)
- {
- *a=*a+*b;
- *b=*a-*b;
- *a=*a-*b;
- }
- OUTPUT:
- enter a choice
- 1.To swap two integers
- 2.To swap of two floats
- 3.To swap of two characters
- 1
- enter two inegers:
- 75
- 84
- value before swapping b= 75 c= 84
- value after swapping b= 84 c= 75
- Press any key to continue
- enter a choice
- 1.To swap two integers
- 2.To swap of two floats
- 3.To swap of two characters
- 2
- enter two floating point numbers:
- 42.6
- 15.4
- value before swapping x= 42.6 y= 15.4
- value after swapping x= 15.4 y= 42.6
- Press any key to continue
- enter a choice
- 1.To swap two integers
- 2.To swap of two floats
- 3.To swap of two characters
- 3
- enter two characters:
- f
- h
- value before swapping p= f q= h
- value after swapping p= h q= f
- Press any key to continue
Advertisement
Add Comment
Please, Sign In to add comment