#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..?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

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

3114


Set up procedure for generating a wire frame display of a polyhedron with the hidden edges of the object drawn with dashed lines

3033


#include int main(void) { int a=4, b=2; a=b<>2 ; printf("%d",a); return 0; }

1075


could you please send the program code for multiplying sparse matrix in c????

3078


write a simple calculator c program to perform addition, subtraction, mul and div.

3155






How can you relate the function with the structure? Explain with an appropriate example.

2923


write a c program to input initial & final time in the format hh:mm and find the time intervel between them? Ex inputs are initial 06:30 final 00:05 and 23:22 final 22.30

2228


how to test pierrot divisor

2264


Write a Program in 'C' To Insert a Unique Number Only. (Hint: Just Like a Primary Key Numbers In Database.) Please Some One Suggest Me a Better Solution for This question ??

1783


Develop a routine to reflect an object about an arbitrarily selected plane

3001


why nlogn is the lower limit of any sort algorithm?

2381


What is data _null_? ,Explain with code when u need to use it in data step programming ?

2828


What is the match merge ? compare data step match merge with proc sql merge - how many types are there ? data step vs proc sql

2414


Given a spherical surface, write bump-mapping procedure to generate the bumpy surface of an orange

2867


To Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates. String contains only lowercase characters ['a'-'z']

506