alinagghiorghita

functia putere

Oct 22nd, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. double putere(int m, int n)
  4. {
  5. int i,c, a = 1;
  6. if (n == 0) return 1;
  7. else if (n > 0) {
  8. for (i = 1;i <= n;i++)
  9. a *= m;
  10. return a;
  11. }
  12. else {
  13. c = (-1)*n;
  14. for (i = 1;i <= c;i++)
  15. a *= m;
  16. return 1.0 / a;
  17. }
  18. }
  19. int main()
  20. {
  21. int e,b;
  22. cout << "b=";cin >> b;
  23. cout << "e=";cin >> e;
  24. cout << putere(b,e) << endl;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment