Home >>Cpp Programs >CPP Program to Calculate Power of a Number
In this example, we will see a C++ program through which we can find the power of a number using a loop.
In this program we will multiply a number (initially with value 1) by the number input by user for N times.
Program:
#include <iostream.h>
using namespace std;
int main()
{
int num;
int a = 1;
int pw;
cout << "Enter a number: ";
cin >> num;
cout << "\n";
cout << "Enter a power : ";
cin >> pw;
cout << "\n";
for (int i = 1; i <= pw; i++) {
a = a * num;
}
cout << a;
return 0;
}