Question: THIS IS A C++ CODE AND I NEED THIS AS A JAVASCRIPT PROGRAM CODE a) The function power1() iteratively compute (x^n) for n>=0. #include using

THIS IS A C++ CODE AND I NEED THIS AS A JAVASCRIPT PROGRAM CODE

a) The function power1() iteratively compute (x^n) for n>=0.

#include

using namespace std;

//power1() function iteratively compute (x^n) for n>=0

int power1(int x,int n)

{

int ans=1,count=0;

if(n>=0)

{

//multiply x by n times

for (int i=0;i

ans = ans*x;

//count by 1 help in determining number of times multiplication done

count=count+1;

}

}

cout<<"No of Multiplication: "<

return ans;

}

int main()

{

int x=3;

int n=3;

b)

#include

using namespace std;

int c=0;

//recursive function power2() compute (x^n)

int power2(int x, int n)

{

//increment c by 1 helps in determining number of multiplication performed

//and determining number of recursive call.

c=::c+1;

if (n==0)

return 1;

else if(n>0){

return x * power2(x,n-1);

}

}

int main()

{

int x=2;

int n=3;

cout<<"Pow "<

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!