1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include<iostream> using namespace std; void swap(int &,int &); int main() { int a,b; cout<<"Enter Value Of A:"; cin>>a; cout<<"Enter Value of B:"; cin>>b; cout<<"Before swapping\nValue of A is "<<a<<"\nValue of B is "<<b; swap(a,b); cout<<"\nOutside function a0fter swapping\nValue of A is"<<a<<"\nValue of B is"<<b; } void swap(int &a,int &b) { int c; c=a; a=b; b=c; cout<<"\nInside function after swapping\nValue of A is"<<a<<"\nValue of B is"<<b; } |
Sample Input
Enter Value Of A:127
Enter Value of B:445
Sample Output
Before swapping
Value of A is 127
Value of B is 445
Inside function after swapping
Value of A is445
Value of B is127
Outside function a0fter swapping
Value of A is445
Value of B is127