P212. WAP to design a macro for swapping of 2 numbers.
#include<stdio.h>
#define
SWAP(a,b,type) { type t; \
t=a; \
a=b; \
b=t; }
void
main()
{
int i=5,j=10;
printf("Before : i = %d j =
%d\n",i,j);
SWAP(i,j,int);
printf("After : i = %d j =
%d\n",i,j);
float f1 = 1.2,f2 = 2.3;
printf("Before : f1 = %f f2 =
%f\n",f1,f2);
SWAP(f1,f2,float);
printf("After : f1 = %f f2 =
%f\n",f1,f2);
}
Comments
Post a Comment