Swap without using third variable

#include <stdio.h>
void main()
{
int a,b;
printf("enter number1: ie a");
scanf("%d",a);
printf("enter number2:ie b ");
scanf("%d",b);
printf(value of a and b before swapping  is a=%d,b=%d"a,b);
a=a+b;
b=a-b;
a=a-b;
printf("value of a and b after swapping  is a=%d,b=%d"a,b);
}

Output:
enter number1:2
enter number2:6
value of a and b before swapping  is a=2,b=6
value of a and b after swapping  is a=6,b=2

ليست هناك تعليقات:

إرسال تعليق