Social Icons

Saturday, 8 February 2014

Program to swap two numbers without using third variable

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

void main()
{
int x,y;
clrscr();
printf("\n\nEnter 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






No comments:

Post a Comment