How to swap two numbers with simple math (+, -) in C

1 Answer

0 votes
#include <stdio.h>
 
int main(void)
{
    int a = 3, b = 7;
    
    printf("a = %d b = %d\n", a, b);
    a = a + b;
    b = a - b;
    a = a - b;
    printf("a = %d b = %d\n", a, b);

    return 0;
}


answered May 6, 2014 by avibootz

Related questions

1 answer 228 views
4 answers 374 views
1 answer 228 views
1 answer 217 views
1 answer 232 views
1 answer 142 views
2 answers 257 views
...