Answer to Question #19226 in C++ for Bhagyashree Shete

Question #19226
int foo(int x, int n)

{

int val = 1;

if (n > 0)

{

if (n % 2 == 1)

val *= x;

val *= foo(x * x, n / 2);

}

return val;

}

What function of x and n is computed by foo?

· xn

· x * n

· nx

· None of the above
1
Expert's answer
2012-11-22T05:56:10-0500
#include<iostream>
using namespace std;

int foo(int x, int n)

{

int val = 1;

if (n > 0)

{

if (n % 2 == 1)

val *= x;

val *= foo(x * x, n / 2);

}

return val;

}

int main ()
{

cout << foo(2,3) << endl;
system ("pause");
return 0;

}

Answer: None of the above

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS