Practical :
Subject : Object Oriented
Programming with C++
Aim : C++ Program to swap two numbers
Source Code :
#include<iostream.h>
#include<conio.h>
void swap(int &a,int &b)
{
int temp;
temp=a;
a=b;
b=temp;
}
void main()
{
clrscr();
int a,b,temp;
cout<<"\n enter a and b \n";
cin>>a>>b;
cout<<"\n before swapping \n";
cout<<"\n a is "<<a<<"\n b is "<<b;
swap(a,b);
cout<<"\n after swapping \n";
cout<<"\n a is"<<a<<"\n b is "<<b;
getch();
}
Output :
0 comments:
Post a Comment