Answer to Question #297304 in C++ for Abel

Question #297304

Write c++ program that find the x raised to the power n use the function concept ,


where n can be any integer. Use the algorithm that would compute x 20 by multiplying


1 by x 20 times

1
Expert's answer
2022-02-13T09:42:17-0500
#include <iostream>




double my_pow(double x , int n )
{
    if (n == 0)
        return 1;
    double res = x;
    for (int i = 1; i < n; i++)
    {
        res *= x;
    }
    return res;
}




int main()
{
    double x;
    int n;


    std::cout << "Enter x : ";
    std::cin >> x;


    std::cout << "Enter n : ";
    std::cin >> n;






    double new_x=my_pow(x, n);


    std::cout << "Result : " << new_x << std::endl;


    return 0;
}

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 the first!

Leave a comment

LATEST TUTORIALS
New on Blog