Swap Numbers Without Using Temporary Variables

an anonymous user · September 15, 2021 · C
#include <stdio.h>

int main() 
{
    int a,b;
    a = 20;
    b = 10;
    
    printf("Before Swapping A = %d; B = %d",a, b);
    a = a - b;
    b = a + b;
    a = b - a;
    
    printf("\n\nAfter Swapping A = %d; B = %d \n\n",a, b);
    return 0;
}

Comments

Please sign up or log in to contribute to the discussion.