write a program to swap two numbers without using variables

answered Oct 11, 2019 by (1,150 points)
#include<stdio.h>

main()

{

int a=10,b=20;

a=a+b-(b=a);

printf("%d %d\n",a,b);

}
commented Oct 13, 2019 by KOTRAGOUDA
20 10  a value will be assign to b then the value of the b will be updated to 10,after that the a value will be calculated
+1 vote
answered Oct 11, 2019 by (360 points)
without third variable we can swap but without any variables we cannt swap in c
answered Oct 11, 2019 by (140 points)
#include<stdio.h>

int main()

{

int first variable ;

int second variable;

printf("change the position of the first variable and second variable with each other");

return 0;

}

;
commented Jun 13 by (2,430 points)
Bro you are awesome
answered Oct 12, 2019 by (520 points)
answered Oct 12, 2019 by anonymous
#include<stdio.h>

#include<conio.h>

int main()

{

int a=1;

int b=2;

a+b

a=(a+b)-a;

b=(a+b)-a;
answered Oct 12, 2019 by (270 points)
#include <stdio.h>
int main()
{
int a,b,temp, *p, *q;
p=&a;
q=&b;
printf("Enter a and b:\n");
scanf("%d%d", &a,&b);
temp=*p;
*p=*q;
*q=temp;
printf("a=%d b=%d",*p,*q);
}
answered Oct 13, 2019 by (150 points)
#include <stdio.h>

int main()
{
int a[2]={1,3};
printf("\n::No.s before swap::\n");
for(int i=0;i<2;i++)
{
printf("%d ",a[i]);
printf("and ");
}
printf("\n::No.s after swap::\n");
for(int i=1;i>=0;i--)
{
printf("%d ",a[i]);
printf("and ");
}

return 0;
}
answered Oct 13, 2019 by (140 points)
#include<stdio.h>

main()

{

int x,y;

x=10,y=20;

x=x^y;;

y=x^y;

x=x^y;

printf("%d  %d",x,y);

}
commented Oct 23, 2019 by Subhadeep Deb Roy
check the 6th line and remove one semicolon ( ; ), else it is perfect
answered Oct 13, 2019 by prince
#include<stdio.h>

void main()

{

int a,b;

printf("enter numbers a b:\n");

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

printf("%d %d\n",a,b);

a=a+b;

b=a-b;

a=a-b;

printf("after swaping:\n");

printf("%d %d\n",a,b)

}
answered Oct 13, 2019 by Abhishek Kumar
#include<stdio.h>

int

{

int a, b;

printf ("enter numbers a,b:\n");

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

printf ("%d %d\n", a, b);

a = a + b;

b = a - b;

a = a - b;

printf ("after swaping:\n");

printf ("%d %d\n", a, b)

}