Skip to content

Instantly share code, notes, and snippets.

@DanielDe
Created October 29, 2012 03:54
Show Gist options
  • Save DanielDe/3971422 to your computer and use it in GitHub Desktop.
Save DanielDe/3971422 to your computer and use it in GitHub Desktop.
CS 10 SI Lab Session 5 - pow
#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