Writing basic instructions



The 'Try Yourself' feature is not available on mobile at the moment.

    // Swapping two variables without third variable    

#include 

int main()
{
    //Declaring variables
    int x, y;

    // Getting input for x
    printf("Enter value for x : ");
    scanf("%d", &x);

    // Getting input for y
    printf("Enter value for y : ");
    scanf("%d", &y);

    // Exchange logic
    x = x + y;
    y = x - y;
    x = x - y;

    // Printing contents of x and y
    printf("x = %d    y = %d", x, y);

    return 0;
}