Header Ads

Swapping Numbers

Swapping without using third variable in C?

swapping means altering the values

Swapping: - Swap x=3 and y=4  after swapping x=4 and y=3

Program

#include<stdio.h>
#include<conio.h>
main()
{
 int x=5,y=7;
 printf("Before swapping\nX=%d & Y=%d",x,y);
 y=x+y;
 x=y-x;
 y=y-x;
 printf("\n\nAfter swapping\nx=%d & y=%d",x,y);
 getch();
}

Output

Before swapping
X=5 & Y=7

After swapping
X=7 & Y=5_


No comments