Swapping means change value of one variable into another variable.
suppose int a=9 int b=7
After swapping b=9 and a=7 .
In this program I have shown how to do swaping of number in c program using function
void swap(int,int); // function name is swap
void main() // opening of main method
{
int a=10,b=20; // initializing variable
clrscr();
swap(a,b); // calling function
getch();
}
void swap(int x, int y)
{
int temp; // declaring temp variable
temp=x; // storing value of x into temp temp=10
x=y; // storing value of y into x x=20
y=temp; // storing vallue of temp which was x value into y y=10
printf("\n a=%d\n b=%d",x,y);
}
0 comments: