Question #30973

write a C++ program which will raise any number x to a positive power n using a for loop?

Expert's answer

#include <iostream>
using namespace std;

int main() {
cout << "Input x: ";
double x;
cin >> x;
cout << "Input n: ";
int n;
cin >> n;
double pow = 1;
for (int i = 0; i < n; i++)
& pow *= x;
cout << pow << endl;
}
LATEST TUTORIALS
APPROVED BY CLIENTS