Created
May 3, 2011 06:16
-
-
Save mbalayil/952885 to your computer and use it in GitHub Desktop.
Swapping without using a temporary variable in C - Addition & Subtraction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Swapping without using a temporary variable in C | |
* (Addition & Subtraction) | |
**/ | |
#include<stdio.h> | |
int main(void) | |
{ | |
int a = 5, b = 10; | |
printf("Initially, a = %d and b = %d\n", a, b); | |
a = a + b; | |
b = a - b; | |
a = a - b; | |
printf("After swapping, a = %d and b = %d\n", a, b); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment