Sunday, December 2, 2012

Swapping using reference variables as arguments in C++


#include<iostream.h>
#include<conio.h>
void swap(int &,int &);
int main()
{
int a,b;
clrscr();
cout<<"enter the values"<<"\n";
cin>>a>>b;
cout<<"Values of a and b before swapping"<<"\n";
cout<<"a="<<a<<"\n"<<"b="<<b;
swap(a,b);
cout<<"\n"<<"The values after exchange are"<<"\n";
cout<<"a="<<a<<"\n"<<"b="<<b;
return 0;
}
void swap(int &c,int &d)
{
int t;
t=c;
c=d;
d=t;
}

No comments:

Post a Comment

DC motor control with Pulse Width Modulation Part 1

DC Motor intro DC motor is a device which converts electrical energy into kinetic energy. It converts the DC power into movement. The typica...