Advertisement
Felanpro

Create your on "power" function.

Aug 14th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.31 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. /*Making my own power function.*/
  6.  
  7. float power(float base, float exponent)
  8. {
  9.     int x = 1;
  10.  
  11.     while(exponent > x)
  12.     {
  13.         base = base * base;
  14.         x++;
  15.     }
  16.  
  17.     return base;
  18. }
  19.  
  20. int main()
  21. {
  22.     cout << power(3, 2) << endl;
  23.  
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement