Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 months ago
467 B
1
Indexable
Never
#include <iostream>
using namespace std;
double power(double A, int B) 
{
    if (B == 0) 
    {
        return 1;
    }
    else {
        double result = A;
        for (int i = 1; i < B; i++) 
        {
            result *= A;
        }
        return result;
    }
}
int main() 
{
    double A;
    int B;
    cin >> A;
    cin >> B;
    double result = power(A, B);
    cout << A << "^" << B << " = " << result << endl;
    return 0;
}
Leave a Comment