Write a C++ Program Calculate Power of a Number

Ram Pothuraju
#include <iostream>
using namespace std;

int main() {
    int exp;

    float base, power = 1;

    cout << "Enter base and exponent respectively:  ";
    cin >> base >> exp;

    while (exp != 0) {
        power *= base;
        --exp;
    }

    cout << "Result = " << power;
    
    return 0;
}


Output

Enter base and exponent respectively:  3.4
3
Result = 39.304

Post a Comment

0Comments

Post a Comment (0)