Tuesday, 21 January 2020

Swapping of two numbers by using third variable in C++

#include<iostream.h>
#include<conio.h>
void swap(int x,int y);
void main()
{
clrscr();
int a,b;
cout<<"enter any two number";
cin>>a>>b;
cout<<"value of a is"<<a<<"\n";
cout<<"value of b is "<<b<<"\n";
swap(a,b);
getch();
}
void swap(int x,int y)
{ int a;
   a=x;
   x=y;
   y=a;
   cout<<"value of a after swapping "<<x<<"\n"<<"value of b after swapiing"<<y;
   }

No comments:

Post a Comment