Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void input(int& base, int& exp);
- int reikningur(int base, int exp);
- void output(int& base, int& exp);
- int main()
- {
- int firstBase, secondExp;
- input(firstBase, secondExp);
- int reikn = reikningur(base, exp);
- output(firstBase, secondExp);
- return 0;
- }
- void input(int& base, int& exp)
- {
- cout << "Base: ";
- cin >> base; //base number (grunntala)
- cout << "Exponent: ";
- cin >> exp; //exponent (veldi)
- }
- int reikningur(int base, int exp)
- {
- for (int i = 1; i < exp; i++)
- {
- exp = base * base;
- }
- return exp; //calculates from the input of the user.2^2 for example...
- }
- void output(int& base, int& exp)
- {
- int ans = pow(base, exp);
- cout << base << " to the power of " << exp << " = " << ans << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement