.: Swap with temp variable :.
#include <stdio.h>
#include <conio.h>
main()
{
int x,y,temp;
Printf("Please Enter values of X and Y for Swapping");
Scanf("%d%d",&x,&y);
Printf("Before Swapping Values of x is %d and y is %d",x,y);
temp=x;
x=y;
y=temp;
printf("Values after Swapping x = %d and Y = %d", x,y);
getch();
return();
}
.: Swap without temp variable :.
#include <stdio.h>
#include <conio.h>
main()
{
int x,y;
Printf("Please Enter values of X and Y for Swapping");
Scanf("%d%d",&x,&y);
Printf("Before Swapping Values of x is %d and y is %d",x,y);
x=x+y;
y=x-y;
x=x-y;
printf("Values after Swapping x = %d and Y = %d", x,y);
getch();
return();
}
#include <stdio.h>
#include <conio.h>
main()
{
int x,y,temp;
Printf("Please Enter values of X and Y for Swapping");
Scanf("%d%d",&x,&y);
Printf("Before Swapping Values of x is %d and y is %d",x,y);
temp=x;
x=y;
y=temp;
printf("Values after Swapping x = %d and Y = %d", x,y);
getch();
return();
}
.: Swap without temp variable :.
#include <stdio.h>
#include <conio.h>
main()
{
int x,y;
Printf("Please Enter values of X and Y for Swapping");
Scanf("%d%d",&x,&y);
Printf("Before Swapping Values of x is %d and y is %d",x,y);
x=x+y;
y=x-y;
x=x-y;
printf("Values after Swapping x = %d and Y = %d", x,y);
getch();
return();
}