Advertisement
lewapkon

potegowanie.cpp

Mar 24th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. /* Autor: Klasa 3C
  2.  Dane: podstawa rzeczywista i naturalny wykladnik potegi
  3.  Wynik 1 liczba rzeczywista - wynik potegowania
  4.  Plik: potegowanie.cpp
  5.  */
  6.  
  7. #include <iostream>
  8.  
  9. using namespace std;
  10.  
  11. int dec2bin(bool tab[], int n) {
  12.     int i = 0;
  13.     while (n > 0) {
  14.         tab[i] = n % 2;
  15.         n /= 2;
  16.         i++;
  17.     }
  18.     return i;
  19. }
  20.  
  21. double potegowanie(int w, double p)
  22. {
  23.     bool tab[255];
  24.     int l = dec2bin(tab, w);
  25.     double s = 1;
  26.     while (l > 0)
  27.         s *= (tab[--l] ? s * p : s);
  28.    
  29.     return s;
  30. }
  31.  
  32. int main ()
  33. {
  34.     int w;
  35.     double p;
  36.     cout << "Podaj podstawe potegi: ";
  37.     cin >> p;
  38.     cout << "Podaj wykladnik potegi: ";
  39.     cin >> w;
  40.     cout << "Wynik potegowania: " << potegowanie(w, p);
  41.    
  42.     cout << endl << endl;
  43.     system("pause");
  44.     return 0;
  45.    
  46.    
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement