Advertisement
MeehoweCK

Untitled

Oct 1st, 2020
606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. double potega ( double x, int d )
  6. {
  7.     if ( d == 0 )
  8.         return 1;
  9.  
  10.     double wynik = 1;
  11.     int i = 0;
  12.     if ( d > 0)
  13.     {
  14.         do
  15.         {
  16.             wynik *= x ;
  17.             i ++;
  18.  
  19.         }
  20.         while (i < d);
  21.         return wynik;
  22.  
  23.     }
  24.     d = -d;
  25.  
  26.     do
  27.     {
  28.         wynik /= x;
  29.         i ++;
  30.     }
  31.     while (i < d);
  32.     return wynik;
  33. }
  34.  
  35. int main()
  36. {
  37.  
  38.     cout << potega (1.5, -3);
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement