Saturday 15 December 2012

C program code for swap the number | example code and comments


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);
}
Share This
Previous Post
Next Post

FYJC XI standard online admisson Process and declaraton of Merit list . Cut off List For prevous year also . 10 Th Results onlne declaraton Maharashtra Region .

0 comments: