Swap two numbers without using third variable

Program:

#include<stdio.h>
int main()
{
 int x,y;
 printf("Enter two numbers: \n");
 scanf("%d %d",&x,&y);
 printf("Before swapping x= %d and y= %d\n",x,y);
 x=x+y;
 y=x-y;
 x=x-y;
 printf("After swapping x= %d and y= %d\n",x,y);
 return 0;

}

Output:



No comments:

Post a Comment

x^y using recursion

Program: #include<stdio.h> int power(int a,int b); int main() { int x,y,ans; printf("Enter x and y:\n "); scanf(...