2,318 views

2 Answers

Best answer
6 6 votes
f(n) = 1, if n=0
f(n) = 2^(n-1), n>=


foo(0) = 1
foo(1) = 1
foo(2) = 2
foo(3) = 4
foo(4) = 8
foo(5) = 16
foo(6) = 32
foo(7) = 64
foo(8) = 128
foo(9) = 256
foo(10) = 512
• selected by
1 1 vote

For foo(x), we need foo(x-i). i is positive, hence for any x we'd need to find the values of foo(<less than x>) to obtain foo(x).

It's best to go with a bottom-up approach, and start with foo(0).

  • foo(0) = 1
  • foo(1) = foo(0) = 1
  • foo(2) = Add all previous values = 2.
  • foo(3) = Add all previous values = 4
  • foo(4) = Add all previous values = 8
  • foo(5) = Add all previous values = 16
  • foo(6) = Add all previous values = 32
  • foo(7) = Add all previous values = 64
  • foo(8) = Add all previous values = 128
  • foo(9) = Add all previous values = 256
  • foo(10) = Add all previous values = 512
Answer:
Position:
Show:

Related questions

13 13 votes
1 answers 1 answer
3.5k
3.5k views
Arjun asked Oct 18, 2016
3,500 views
#include <stdio.h int foo(int a[100]) { return sizeof(a); } int main() { int a[10]; printf("%d", foo(a)); }What will be the output of the above code ignoring any compiler...
5 5 votes
4 answers 4 answers
2.7k
2.7k views
Arjun asked Oct 18, 2016
2,689 views
What will be returned by the following function foo when called as foo(10)?int foo(int n) { return n & n | 1; }
4 4 votes
2 answers 2 answers
2.3k
2.3k views
Arjun asked Oct 18, 2016
2,348 views
No. of times '*' will be printed by the following C code is _____#include<stdio.h void foo(int x) { switch(x){ case 1: printf("*"); case 2: printf("*"); case 3: printf("*...
7 7 votes
4 answers 4 answers
3.5k
3.5k views
Arjun asked Oct 18, 2016
3,530 views
The output of the following C program will be _____#include<stdio.h #define type int type foo(type b) { return b*b; } #undef type #define type float int main() { float a ...