Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Autor: Klasa 3C
- Dane: podstawa rzeczywista i naturalny wykladnik potegi
- Wynik 1 liczba rzeczywista - wynik potegowania
- Plik: potegowanie.cpp
- */
- #include <iostream>
- using namespace std;
- int dec2bin(bool tab[], int n) {
- int i = 0;
- while (n > 0) {
- tab[i] = n % 2;
- n /= 2;
- i++;
- }
- return i;
- }
- double potegowanie(int w, double p)
- {
- bool tab[255];
- int l = dec2bin(tab, w);
- double s = 1;
- while (l > 0)
- s *= (tab[--l] ? s * p : s);
- return s;
- }
- int main ()
- {
- int w;
- double p;
- cout << "Podaj podstawe potegi: ";
- cin >> p;
- cout << "Podaj wykladnik potegi: ";
- cin >> w;
- cout << "Wynik potegowania: " << potegowanie(w, p);
- cout << endl << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement