Consider we have two variables x and y containing some number. We are asked to swap the values without using a third variable. To solve this problem we follow the given steps (algorithm)

```
x = x + y
y = x - y
x = x - y
```

```
Let x = 10 and y = 20
So,
x = x + y
= 10 + 20
= 30
y = x - y
= 30 - 20
= 10
x = x - y
= 30 - 10
= 20
```

```
Let x = 10 and y = -20
So,
x = x + y
= 10 + (-20)
= -10
y = x - y
= (-10) - (-20)
= (-10) + 20
= 10
x = x - y
= (-10) - 10
= -20
```

```
Let x = -10 and y = -20
So,
x = x + y
= (-10) + (-20)
= -30
y = x - y
= (-30) - (-20)
= (-30) + 20
= -10
x = x - y
= (-30) - (-10)
= (-30) + 10
= -20
```

```
#include <stdio.h>
int main(){
//variables
int x, y;
//input
printf("Enter value of x and y: ");
scanf("%d%d", &x, &y);
//swap
x = x + y;
y = x - y;
x = x - y;
//output
printf("x = %d y = %d\n", x, y);
return 0;
}
```

Recently Added

- Bootstrap - Dropdowns Bootstrap
- Bootstrap - Panels Bootstrap
- Bootstrap - List group Bootstrap
- Bootstrap - Media Object Bootstrap
- Bootstrap - Thumbnails Bootstrap
- Upload file to remote server using FTP and SFTP Client - Windows, Mac, Linux Howto Website
- Setting up name servers - Pointing domain name to hosting server Howto Website
- Getting a domain and hosting plan for your website Howto Website
- Getting started with free blog and website Howto Website
- How to Website - Introduction Howto Website