How to swap two numbers using C language



#include<stdio.h>
int main()
{
 int x,y,temp;
 printf("enter the value of x and y :\n");
 scanf("%d %d",&x,&y);
 printf("before swapping\nx=%d\ny=%d\n",x,y);
 temp=x;
 x=y;
 y=temp;
 /* using this temp to swap storing x to temp and y to x then moving temp to y */
 printf("after swapping\nx=%d\ny=%d\n",x,y);

}

OUTPUT

SHARE WITH YOUR FRIENDS

No comments:

Post a Comment