mcqs bucket

  • MCQs Bucket | Program Write a Program in C++ that Calculate Power of a Number

    mcqsbucket

      Best guide for exams of all nature, Competitive exams and Interviews

Write a Program in C++ that Calculate Power of a Number

	 
                                 		
#include <iostream>
using namespace std;

int main() 
{
    int exponent;
    float base, result = 1;

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

    cout << base << "^" << exponent << " = ";

    while (exponent != 0) {
        result *= base;
        --exponent;
    }

    cout << result;
    
    return 0;
}