Wednesday, 11 February 2015

u3p3

Write a program using a function with arguments to swap the values of a pair of integers using call by reference.



 #include<iostream.h>  
 #include<conio.h>  
 void swap_fun(int x, int y)  
 {  
       int temp;  
       temp = x;  
       x = y;  
       y = temp;  
       cout<<"\nValues after the swap : \nX = "<<x<<", Y = "<<y;  
 }  
 void main()  
 {  
       clrscr();  
       int x, y;  
       cout<<"Enter value for swap : \nEnter value of X = ";  
       cin>>x;       
       cout<<"Enter value of Y = ";  
       cin>>y;  
       swap_fun(x,y);  
       getch();  
 }  

OUTPUT : 

No comments:

Post a Comment