Advertisement
Guest User

zad9cw10

a guest
Nov 25th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int liczba;
  6. int potega;
  7.  
  8. void wczytaj()
  9. {
  10.     cout << "Podaj liczbe: ";
  11.     cin>>liczba;
  12.  
  13.     cout << "Podaj potege: ";
  14.     cin>>potega;
  15. }
  16.  
  17. void potegowanie(int l,int p)
  18. {
  19.     float s=1;
  20.     if(p>0)
  21.     {
  22.         for(int i=1;i<=p;i++)
  23.         {
  24.             s=s*l;
  25.         }
  26.  
  27.         cout<<"Wynik: "<<s<<endl;
  28.     }
  29.     else  if(p==0){cout<<"Wynik: "<<s<<endl;}
  30.     else
  31.         {
  32.           for(int i=-1;i>=p;i--)
  33.           {
  34.               s=s*l;
  35.           }
  36.  
  37.           float w=1.0/s;
  38.           cout<<"Wynik: "<<(float)w<<endl;
  39.         }
  40. }
  41.  
  42. int main()
  43. {
  44.     wczytaj();
  45.     potegowanie(liczba,potega);
  46.  
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement