Saturday, February 24, 2024

8. Write a macro that swaps two numbers. WAP to use it.

 #include <stdio.h>


#define SWAP(x, y) (x ^= y ^= x ^= y)


int main()

{

    int num1, num2;


    

    printf("Enter any two number to swap: ");

    scanf("%d%d", &num1, &num2);


    printf("Values before swapping\n");

    printf("num1 = %d, num2 = %d\n\n", num1, num2);


    SWAP(num1, num2);


    printf("Values after swapping\n");

    printf("num1 = %d, num2 = %d\n", num1, num2);


    return 0;

}

No comments:

Post a Comment