Saturday, 23 September 2017

C program to swap two numbers without using temporary variable

C program to swap two numbers without using temporary variable
#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();
}

0 comments:

Post a Comment

Tech UOG