Monday, May 2, 2011

Swapping without using temporary variable in C - Addition & Subtraction

/**
* 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;
}
view raw swap_add_mul.c hosted with ❤ by GitHub
Written by

No comments:

Post a Comment