Re: Please Solve this C program
There are two solution i can give.
1.Solution:
static int a=5,b=6,temp;
#define swap(a,b)temp=a;a=b;b=temp;
int main()
{
if(a>b)
{
swap(a,b)
}
printf("a=%d b=%d",a,b);
return(0);
}
The o/p is a=5 ,b=6
2. Solution:
static int a=5,b=6,temp;
#define swap(a,b) { temp=a;a=b;b=temp; }
int main()
{
if(a>b)
swap(a,b)
printf("a=%d b=%d",a,b);
return(0);
}
The o/p is a=5 ,b=6
The problem was the #define instruction (preprossor) didn't close well...
Try this:
static int a=5,b=6,temp=99;
#define swap(a,b)temp=a;a=b;b=temp;
int main()
{
if(a>b)
swap(a,b)
printf("a=%d b=%d",a,b);
return(0);
}
The o/p is a=6 ,b=100
__________________
Always look at what you have left.Never look at what you have lost
|