You are on page 1of 2

Swapping without third variable

#include <stdio.h>

int main()

int a,b;

printf("Enter two numbers to be swaped");

printf("\n");

scanf("%d%d",&a,&b);

printf("A is");

printf("%d",a);

printf("\n");

printf("B is");

printf("%d",b);

printf("\n");

a=a+b;

b=a-b;

a=a-b;

printf("Now the numbers have been swapped");

printf("\n");

printf("A is now");

printf("%d",a);

printf("\n");

printf("B is now");

printf("%d",b);

return 0;

You might also like