The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
0 votes
110 views
void PrintValue(int n) {

           if (n < 0) return;

           else {

                  printf(n);

                  PrintValue(--n);

                  PrintValue(n--);

                  printf(n);

                 }

   }

Output for Print(5) ?
asked in Programming by Loyal (6.6k points)
edited by | 110 views
0
543210 100 2101001 321010012 432101001234 ??
0
Sorry i just forgot to mention here you need to print the sum of values Printed :

Answer is 52
0
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
I think the variable is local only. it is not ur case.
0
It's the exact program brother

2 Answers

+1 vote
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
answered by (83 points)
0 votes
In printf(n)  ,

where is your format specifier ?

 

please corrects  the code .
answered by (21 points)
0
Its made easy question assume everything is given as default focus only on output behavior :)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
49,811 questions
54,536 answers
188,423 comments
75,593 users