in Programming edited by
406 views
0 votes
0 votes
void PrintValue(int n) {

           if (n < 0) return;

           else {

                  printf(n);

                  PrintValue(--n);

                  PrintValue(n--);

                  printf(n);

                 }

   }

Output for Print(5) ?
in Programming edited by
by
406 views

4 Comments

I have one doubt when n will be taken at 0 then it will print -ve values and if u keep on doing that the sum is coming negative -12.

I did by forming recursive tree, i'll post in a while
0
0
I think the variable is local only. it is not ur case.
0
0
It's the exact program brother
0
0

2 Answers

2 votes
2 votes
5+4+3+2+1+0+(-2)+0+(-2)+(-1)+1+0+(-2)+0+(-2)+(-1)+0+2+1+0+(-2)+0+(-2)+(-1)+1+0+(-2)+0+(-2)+(-1)+0+1+3+2+1+0+(-2)+0+(-2)+(-1)+1+0+(-2)+0+(-2)+(-1)+0+2+1+0+(-2)+0+(-2)+(-1)+1+0+(-2)+0+(-2)+(-1)+0+1+2+4+3+2+1+0+(-2)+0+(-2)+(-1)+1+0+(-2)+0+(-2)+(-1)+0+2+1+0+(-2)+0+(-2)+(-1)+1+0+(-2)+0+(-2)+(-1)+0+1+3+2+1+0+(-2)+0+(-2)+(-1)+1+0+(-2)+0+(-2)+(-1)+0+2+1+0+(-2)+0+(-2)+(-1)+1+0+(-2)+0+(-2)+(-1)+0+1+2+3

 

-12 is the answer
0 votes
0 votes
In printf(n)  ,

where is your format specifier ?

 

please corrects  the code .

1 comment

Its made easy question assume everything is given as default focus only on output behavior :)
0
0

Related questions