AnkitWebLogic

Swap numbers without using 3rd variable

Q12. WAP to Input two numbers and swap them without using 3rd variable. 1

#include<stdio.h>
void main()
{
	int a, b, c;
    printf("\nEnter two numbers:");
    scanf("%d%d",&a,&b);
    b=a+b;
    a=b-a;
    b=b-a;
    printf("A = %d\n",a);
    printf("B = %d",b);
}
Enter two numbers: 10
20
A = 20
B = 10

Advertisement