#include(iostream.h) // place this '<' & '>' instead of '(' & ')' before iostream.h
#include(conio.h)
void swap(int, int);
void main( )
{
int x, y;
clrscr( );
cout<<"Enter the two numbers to swap:"; cin>>x >>y;
swap(x, y);
getch( );
}
void swap( int a, int b)
{
int temp;
cout<<"Values before swapping: "<< a <<"and"<< b;
temp=a;
a=b;
t=temp;
cout<<"Vaues after swapping:" << a <<"and"<< b;
}
Output: Enter the two numbers to swap: 10 20
Values before swapping: 10 and 20
Values after swapping: 20 and 10
Note:- If u have any doubt regarding this program or logic, please feel free to contact me.
Thursday, February 26, 2009
Subscribe to:
Post Comments (Atom)
This comment has been removed by the author.
ReplyDeletethis link might be help you C program to swap two numbers
ReplyDeletehttp://programmergallery.com/c-program/c-program-swap-two-numbers.php
it is not easy way
ReplyDelete