Advertisement
Guest User

Untitled

a guest
Sep 17th, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void input(int& base, int& exp);
  6. int reikningur(int base, int exp);
  7. void output(int& base, int& exp);
  8.  
  9. int main()
  10. {
  11. int firstBase, secondExp;
  12. input(firstBase, secondExp);
  13.  
  14. int reikn = reikningur(base, exp);
  15.  
  16. output(firstBase, secondExp);
  17.  
  18. return 0;
  19. }
  20.  
  21. void input(int& base, int& exp)
  22. {
  23. cout << "Base: ";
  24. cin >> base; //base number (grunntala)
  25. cout << "Exponent: ";
  26. cin >> exp; //exponent (veldi)
  27. }
  28.  
  29. int reikningur(int base, int exp)
  30. {
  31. for (int i = 1; i < exp; i++)
  32. {
  33. exp = base * base;
  34. }
  35. return exp; //calculates from the input of the user.2^2 for example...
  36. }
  37.  
  38. void output(int& base, int& exp)
  39. {
  40. int ans = pow(base, exp);
  41. cout << base << " to the power of " << exp << " = " << ans << endl;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement