external_7.c (524B)
1 // 7. Write a program to swap two numbers using a macro. 2 3 #include<stdio.h> 4 5 #define SWAP(a, b) \ 6 do { \ 7 __typeof__(a) temp = a; \ 8 a = b; \ 9 b = temp; \ 10 } while (0) \ 11 12 int main() { 13 int a, b; 14 printf("Enter two number: "); 15 scanf("%d %d", &a, &b); 16 printf("\nA = \'%d\', B = \'%d\'", a, b); 17 SWAP(a, b); 18 printf("\nA = \'%d\', B = \'%d\'", a, b); 19 return 0; 20 }