Answer to Question #30973 in C++ for SOLOMON

Question #30973
write a C++ program which will raise any number x to a positive power n using a for loop?
1
Expert's answer
2013-06-04T08:16:14-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS