Answer to Question #19226 in C++ for Bhagyashree Shete
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
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!
Learn more about our help with Assignments:
C++
Comments
Leave a comment