Showing posts with label values. Show all posts
Showing posts with label values. Show all posts
Saturday, February 14, 2015
C program to swap values of two variables using pass by reference method

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
void swap(int &,int &);
cout<<"Enter two values:";
cin>>a>>b;
cout<<"
Befor swapping:
a="<<a<<" b="<<b;
swap(a,b);
cout<<"
After swapping:
a="<<a<<" b="<<b;
getch();
}
void swap(int & x,int & y)
{
int temp;
temp=x;
x=y;
y=temp;
}
Subscribe to:
Posts (Atom)