View Single Post
Old 01-04-06, 02:40 AM   #5 (permalink)
Jyoti Bhatnagar
Member
 
Join Date: Mar 2006
Location: India
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 3 Jyoti Bhatnagar has disabled reputation


Hi,


As per question provided we have to use user defined function. So correct way could be as given by harishmitty using 3rd variable or as following


#include<stdio.h>


void main()
{
int M = 5, N = 3;


void swap (int m,int n);
printf("\nBefore Swap ");
printf("\n\tM=%d\tN=%d",M,N);
swap (M,N);


getch();


}
void swap(int m, int n)


{


m=m + n;
n = m - n;
m =m - n;


printf("\nAfter Swap ");
printf("\n\tm=%d\tn=%d",m,n);
}
__________________
Jyoti Bhatnagar
Jyoti Bhatnagar is offline   Reply With Quote