# write a program to swap two numbers without using variables

asked Oct 10, 2019

answered Oct 14, 2019 by (190 points)
#include<stdio.h>

void main()

{

int a,b;

a=5;b=10;

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

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

getch();

}
answered Oct 16, 2019 by (140 points)
#include<stdio.h>

int main()

{

int a,b;

printf("\n Input integers to swap two integers (a,b)");

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

a=a+b;

a=a-b;

printf("\n After swapping ",a,b);

}
commented Oct 17, 2019 by anonymous
#include<stdio.h>

int main()

{

int x,y;

printf("\n Input integers to swap two integers (x,y)");

scanf("%d%d",&x,&y);

x=x*y;

y=x/y;

x=x/y;
printf("\n After swapping ",x,y);

}
answered Dec 22, 2019 by anonymous
x = 5

y = 6

(x,y) = (y,x)

print ("X value is " + x + "Y value is " + y )
answered Dec 28, 2019 by (140 points)
//program without using third variable

#include<stdio.h>

main()

{

int a=10,b=20;

a=a+b;     // here a becomes a=30

b=a-b;      // here b=30-20=10        b=10

a=a-b;      //here  a=30-10=20        a=20   (since b became b=10 in before condition)

printf("after swaping values are %d and %d",a,b);

}
answered Dec 30, 2019 by (140 points)
#include<stdio.h>

int main()

{

int a=5,b=10;

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

printf("after sort   ");

a=a+b;

b=a-b;

a=a-b;

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

}
answered Jun 13 by (470 points)
#include <stdio.h>
main()
{
int a,b;
printf("enter the value of a\n");
scanf("%d",&a);
printf("enter the value of b\n");
scanf("%d",&b);
a=a+b;
b=a-b;
a=a-b;
printf("after swapping is %d\n%d\n",a,b);

}
answered Jun 20 by (140 points)
#include<stdio.h>

void main()

{ int a, b

printf("enter the first number:");

scanf("%d"; &a);

printf("enter the second number:")

scanf("%d",&b);

a = a+b;

b= a-b;

a=a-b;

printf(" the swapped numbers are :", a,b);

}
answered Jun 23 by (140 points)
#include <stdio.h>
#include <iostream>
#include <utility>

std::pair <int, int> SwapTheseNumbersForNoReason(int a, int b) {
return {b, a};
}

int main()
{
std::pair <int, int> swapped = SwapTheseNumbersForNoReason(69, 42);
std::cout << "New first: " << swapped.first << " - New second : " << swapped.second << std::end;
return 0;
}