C program to swap two numbers without using a temporary variable

Program

#include<stdio.h>
#include<conio.h>

void main()
{
int x,y;
clrscr();
printf(“Enter value of X: “);
scanf(“%d”,&x);
printf(“Enter value of y: “);
scanf(“%d”,&y);

if(x>y)
{
y=x-y;
x=x-y;
y=x+y;
}

else
if(y>x)
{
x=y-x;
y=y-x;
x=y+x;
}

printf(“nx=%d”,x);
printf(“ny=%d”,y);
getch();
}

Output

Leave a Comment

error: Alert: Content is protected!!