Answer is 9

1 vote

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

{

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

0

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

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.

.

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

3 votes

#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

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