Question

int Func( * in */ inta, /* in */ int b) { int result=0; if (b == 0 ) // base case result = a; else if (b>0) // first generalWhen Func (20,5) is called: Return Result a b Return Result CH W b Return Result a b Return Result

0 0
Add a comment Improve this question Transcribed image text
Answer #1

a=160 b=0 result=160
a=80 b=1 result=400
a=40 b=2 result=520
a=20 b=5 result=580
final return 580+20 which is 600 is answer

#code in c++

1 2 3 4. 5 6 7 8 9 10 11 12 13 14 #include <iostream> using namespace std; int Func(int a, int b) [ int result=0; if(b==0) re

#if you have any doubt or more information needed comment below..i will respond as possible as soon..thanks...

Add a comment
Know the answer?
Add Answer to:
int Func( * in */ inta, /* in */ int b) { int result=0; if (b...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Convert the following C code into ARM int foo(int a, int b) { int result =...

    Convert the following C code into ARM int foo(int a, int b) { int result = 0; int i; for (i = 20; i <= 30; i++) { if (i == 24) result += 20; else if (i == 27) result = result * 2; else result = result + a + 3*b; } return result; }

  • b) Consider the following code. public static int f(int n) if (n == 1) return 0;...

    b) Consider the following code. public static int f(int n) if (n == 1) return 0; else if (n % 2 == 0). return g(n/2); else return g(n+1); public static int g(int n) int r = n % 3; if (r == 0) return f(n/3); else if (r == 1) return f(n+2); else return f(2 * n); // (HERE) public static void main(String[] args) { int x = 3; System.out.println(f(x)); (1) (5 points) Draw the call stack as it would...

  • 24) (3x2 marks) Consider the following method: public static int mysteryl (int a, int b) (...

    24) (3x2 marks) Consider the following method: public static int mysteryl (int a, int b) ( int result 0: if (a <b) ( else if (a b) else ( return result: result mystery2 (a) mystery2 (a)i result - mystery2 (b) result-ab; public static int mystery2 (int x) f int countx for (int i 0; іск; i++) count +1: return counti What are the values stored in the variable result after the following method calls? a) int result mysteryl(4,1): b) int...

  • long fib(int n) { long result;    if (n==0) result = 0; else if (n==1 ||...

    long fib(int n) { long result;    if (n==0) result = 0; else if (n==1 || n==2) result = 1; else result = fib(n-1) + fib(n-2);    return result; } [C language] Question : Why is this code is so slow? Explain ex2) Make the program from exercise 1 faster by trading space for time. Create an array of int that can be used as a cache. Each index in the array should correspond to a value that you can...

  • Convert the following program into MIPS Instructions: int a = 0; int b = 10; int...

    Convert the following program into MIPS Instructions: int a = 0; int b = 10; int c = 100; result = isSorted(a, b, c); if (!result) isSorted(c, b, a); int isSorted(int a, int b, int c) {if (a < b && b < c) return 1; else return 0;}

  • What is the value of  result after the following code executes?   int a = 60; int b...

    What is the value of  result after the following code executes?   int a = 60; int b = 15; int result = 20; if (a = b) result *= 3; 30 20 60 10 code will not execute The numeric data types in C++ can be broken into two general categories which are integers and floating-point numbers singles and doubles real and unreal numbers numbers and characters numbers and literals Which line in the following program will cause a compiler error?...

  • 3 What is the result of calling a - ( rFunction(5, -1);? 4. Which of the...

    3 What is the result of calling a - ( rFunction(5, -1);? 4. Which of the following is NOT a part of a recursive func- tion? A. function call B. stopping case C. stopping criteria D. update for the test variable E. None of the above 5 A stack overtiow error is when the A. amount of memory in the stack exceeds the the memory available B. number at recursive steps needed to complete the tasks exceeds the available time....

  • Consider the following in C int main() { float x = 3.14, *p = &x; int...

    Consider the following in C int main() { float x = 3.14, *p = &x; int r, a = 2, b[] = {5, 6, 7}; <more code here> r = Foo(x, p, &a, b) <more code here> } int Foo(float x,float y, int *z, int *w) { <Foo's code goes here> } statement in Foo result (assigned value) modify Foo's AF variables modify main's AF variables statement in Foo result (assigned value) modify Foo's AF variables modify main's AF variables...

  • Java code efficiency: Look at the implementation of the method called intervalSums below. Design and implement...

    Java code efficiency: Look at the implementation of the method called intervalSums below. Design and implement a more efficient runtime algorithm for intervalSums. public static long intervalSums(intll A, intl0 B) long count = 0; for (int i = 0; i < A.|ength; i++) { for (int j = i; j < A.length; j++) { int sum = 0; for (int k = i; k <= j; k++) { sum += A[k]; count += 1; B[i][j] = sum; if (j >...

  • 2. Consider the following programs (using C's syntax): #include <stdio.h> int a- 1, b-2; int foo...

    2. Consider the following programs (using C's syntax): #include <stdio.h> int a- 1, b-2; int foo (int x) 1 return (x+a); void ba r () { printf("%d, %d\n",a,b); void foobar) } printf("%d, %d\n", a, b) ; int a -4; bar bfoo (b); bar int main)( int b 8; foobar printf ("%d, %d\n", a, b) ; return 0; (a) What does the program print under static scoping? (b) What does the program print under dynamic scoping?

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT