#include<stdio.h>
void fun(int);
int main()
{
int a;
a=3;
fun(a);
printf("\n");
return 0;
}
void fun(int i)
{
if(n>0)
{
fun(--n);
printf("%d",n);
fun(--n);
}
} the answer is 0 1 2 0..someone explain how the code is
executed..?



#include<stdio.h> void fun(int); int main() { int a; a=3; fun(a); printf("\n"..

Answer / siva kumar

for example :
Here a is three(3).

calling fun(3) in main function.
FUN(3) {
calling fun(2) {
calling fun(1) {
calling fun(0) {
N>0 found.
}
printed 0
calling second fun(-1) {
N>0 found.
}
}
printed 1
calling second fun(0) {
N>0 found.
}
}
printed 2
calling second fun(1) {
calling fun(0) {
N>0 found.
}
printed 0
calling second fun(-1) {
N>0 found.
}
}
}

Is This Answer Correct ?    27 Yes 12 No

Post New Answer

More C Code Interview Questions

why is printf("%d %d %d",i++,--i,i--);

4 Answers   Apple, Cynity, TCS,


#include<stdio.h> main() { register i=5; char j[]= "hello"; printf("%s %d",j,i); }

2 Answers  


void main() { unsigned giveit=-1; int gotit; printf("%u ",++giveit); printf("%u \n",gotit=--giveit); }

1 Answers  


main() { int i = 3; for (;i++=0;) printf(ā€œ%dā€,i); }

1 Answers   CSC,


posted by surbhi just now main() { float a = 5.375; char *p; int i; p=(char*)&a; for(i=0;i<=3;i++) printf("%02x",(unsigned char) p[i]); } how is the output of this program is :: 0000ac40 please let me know y this output has come

2 Answers   GATE,






void main() { int k=ret(sizeof(float)); printf("\n here value is %d",++k); } int ret(int ret) { ret += 2.5; return(ret); }

1 Answers  


write a c program to Create a registration form application by taking the details like username, address, phone number, email along with password and confirm password (should be same as password).Ensure that the password is of 8 characters with only numbers and alphabets. Take such details for 5 users and display the details. In place of password display ā€œ****ā€. (Use Structures).

0 Answers   CDAC, College School Exams Tests,


how to check whether a linked list is circular.

11 Answers   Microsoft,


Cluster head selection in Wireless Sensor Network using C programming language.

0 Answers  


main() { int k=1; printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE"); }

1 Answers  


Write a program to receive an integer and find its octal equivalent?

7 Answers  


main() { printf("\nab"); printf("\bsi"); printf("\rha"); }

3 Answers  


Categories