Program to swap two numbers using macros.
// Program to swap two numbers using macros.
#include<stdio.h>
#define swap(a, b) int t=a; a=b; b=t;
int main() {
int a, b;
printf("Enter two numbers : ");
scanf("%d%d", &a, &b);
printf("Before swapping a = %d, b = %d\n", a, b);
swap(a, b);
printf("After swapping a = %d, b = %d", a, b);
return 0;
}
Output :
Enter two numbers : 5 7
Before swapping a = 5, b = 7
After swapping a = 7, b = 5
No comments:
Post a Comment