Program 2
Power Function
Given Function/method pow need to return the x raised to the power n, with the help of stl function. You are required to fix logical errors in given code.
Note : Use STL Function only similar to power.
Input: x = 2.00000, n = 10
Expected Output: 1024.00000
Current output: 10.0000
Incorrect Code
Correct Code
Incorrect Code
double myPow(double x, int n) { return (x,n); }
Correct Code
#include <bits/stdc++.h> double myPow(double x, int n) { return pow(x,n); }
#include
#include
double myPow(double x, int n) {
return pow(x,n);
}
#include
public class calculatePower{
public static int mypow(double x,int n){
if(n == 0){
return 1;
}
if(x == 0){
return 0;
}
return (int )x * mypow(x, n-1);
}
#include
using namespace std;
#include
Hey there,
Thanks for commenting.🙌💚