#include<stdio.h>
#include<conio.h>
# define swap(a,b) temp=a; a=b; b=temp;
void main( )
{
int i, j, temp;
i=5;
j=10;
temp=0;
if( i > j)
swap( i, j );
printf( "%d %d %d", i, j, temp);
}
Answers were Sorted based on User's Feedback
Answer / rohit751
Hi all...the main mistake in the program is using the semi
colons in the macro definition. Try this..
#include<stdio.h>
#include<conio.h>
# define swap(a,b) temp=a, a=b, b=temp;
void main( )
{
int i, j, temp;
i=5;
j=10;
temp=0;
if( i < j)
swap( i, j );
printf( "%d %d %d", i, j, temp);
}
Is This Answer Correct ? | 10 Yes | 0 No |
Answer / ashish rajvanshi
My dear frnds its a simple question
here the code of macro inserted in the program at the time of preprocessing and then the calculation will performed.
and then it will be calculated.
void main()
{
int i,j, temp;
i=5;
j=10;
temp=0;
if(i>j)
temp=a;
a=b;
b=temp;
printf("%d %d %d" , i , j , temp);
}
for further detail contect at(ashish.raj.mrt@gmail.com)
Is This Answer Correct ? | 3 Yes | 1 No |
Answer / ashishrajvanshi01
On compiling i got ans 10, 0, 0. I did not understand the concept. Please expalin this to me.
Is This Answer Correct ? | 5 Yes | 4 No |
Answer / harish
it enters into swap function only when i>j.
but i contains 5 and j contains 10.
can u plz explain this
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / abhijeet
my frnd, C is dumb compiler. It doesn't know what actually
we mean.
Here, in this program, we have defined 1 macro. Ok
this macro wil be inserted and expanded into code.
this gives the unpredicted result. U try and find out what i
mean to say.
Is This Answer Correct ? | 1 Yes | 1 No |
Answer / kumaravel
chance of providing answer is not possible. empty screen become view.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / manish soni tagore collage jai
my dear frd....
here some hapen.
#define swap(a,b) temp=a;a=b;b=temp;----------(1)
is was as function of swap two no;(but it is differnt frm
funtion.)
so
at i>j;
enter swap(i,j);
so jump at eq(n) ---(1) and call swap function'
and
temp=5;
i=10;
j=0;
you see three variable.
but it printf i,j to convert swap.
bcoz it have two arguments.
and print temp=0;
becoz temp have 0;
Is This Answer Correct ? | 0 Yes | 7 No |
int n=1; while(1) { switch(n) { case 1:printf("a"); n++; continue; case 2:printf("b"); n++; continue; default : printf("c"); break; } break; }
which type of aspect you want from the student.
In this problem you are to write a program that will cut some number of prime numbers from the list of prime numbers between 1 and N.Your program will read in a number N; determine the list of prime numbers between 1 and N; and print the C*2 prime numbers from the center of the list if there are an even number of prime numbers or (C*2)-1 prime numbers from the center of the list if there are an odd number of prime numbers in the list.
application of static variables in real time
a<<1 is equivalent to a) multiplying by 2 b) dividing by 2 c) adding 2 d)none of the above
what would be the output of the following prog? Justify your answer? main() { unsigned char ch; unsigned char i; ch = -255; printf("%d",ch); i = -1; printf("%d",i); }
Write a programm such that if user enter 11.25 it roundup to 11 but if user enter 11.51 upto 11.99 it will round up to 12 i.e.;convert the floting point value into integer format as explain above..
How can variables be characterized?
Explain what’s a signal? Explain what do I use signals for?
If we have an array of Interger values, find out a sub array which has a maximum value of the array and start and end positions of the array..The sub array must be contiguious. Take the start add to be 4000. For Ex if we have an array arr[] = {-1,-2,-5,9,4,3,-6,8,7,6,5,-3} here the sub array of max would be {8,7,6,5} coz the sum of max contiguous array is 8+7+6+5 = 26.The start and end position is 4014(8) and 4020(5).
5 Answers Microsoft, Motorola,
What are the two forms of #include directive?
for example user gives input as " 20 or 20.0 or rs 20.0 or 20.00 or rs20 and so .. on " and the output should be stored as " rs.20.00 " in a variable