Created
October 29, 2012 03:54
-
-
Save DanielDe/3971422 to your computer and use it in GitHub Desktop.
CS 10 SI Lab Session 5 - pow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
double b; | |
cout << "Please enter a base number: "; | |
cin >> b; | |
int e; | |
cout << "Please enter an exponent: "; | |
cin >> e; | |
if (e < 0) { | |
e *= -1; | |
b = 1 / b; | |
} | |
double result = 1; | |
for (int i = 0; i < e; ++i) | |
result *= b; | |
cout << "Result = " << result << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment