# pseudo code

1 vote
309 views
int  zap(int n)
{
if (n<=1) then zap =1;
else zap = zap(n-3)+zap(n-1);
}
then the call zap(6) gives the values of zap

Give the proper explanation

edited
0
0
it will lead to compile time error.
0
how.explanation required
0
They asked  what  is  value ...
0
but its zap = zap(n-3)+zap(n-1) : lvalue will be needed
0

@arvin

zap is undeclared, therefore it will lead to compiler error, but that is not complete program, therefore we can assume zap is declared...

moreover there is no problem having variable same as function name with in that function, so the answer is 9

0
how did you solve it to get the answer 9 m seeking for the complete stepwise solution.
0
the function does not return any value ... so do we have to assume that also
0

@Shiv Gaur

yes we have to assume that, function return the value also...

otherwise how we will compute n>2 ?

1
@shaikh i dont know but i think it wont execute as how can zap be a variable and function at the same time..

.

dont u think zap(n)= zap(n-3)+zap(n-1) should be the right way.
0
indeed I also  know that this is not going to execute that's why I am demanding for the correct code you can modify it to make it workable
0

is it your self doubt? or somewhere you got this question?

if somewhere you got this question, what is the answer provided by them.

#include<stdio.h>
int zap(int n)
{
int p;
if(n<=1)
p=1;
else
p=zap(n-3)+zap(n-1);
return p;
}
int main()
{
int p=zap(6);
printf("%d",p);
}

p will be

p=zap(0) + zap(-1) +zap(1) +zap(-1) +zap(1) +zap(1) +zap(0) +zap(-1) +zap(1)

p=1+1+1+1+1+1+1+1+1=9;

i think this should be solution of this question...

plz tell me if there is wrong any thing in this explanation

## Related questions

1
800 views
Output of this program - int rec(int x) { static int f; if(x == 1) return(1); else __Y__ ; return f ; } What is the value returned by rec(5) &#8203;a) when Y is f = f * 1 + rec(x-1) ; b) when Y is f = f * x + rec(x-1) ; What is proper way to solve this ?