fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. double a;
  6. int n;
  7.  
  8. cout << "enter a real number a: ";
  9. cin >> a;
  10.  
  11. cout << "enter an integer n: ";
  12. cin >> n;
  13.  
  14. double result = 1;
  15.  
  16. if (n >= 0) {
  17. for (int i = 0; i < n; i++) {
  18. result *= a;
  19. }
  20. } else {
  21. for (int i = 0; i < -n; i++) {
  22. result *= a;
  23. }
  24. result + 1 / result;
  25. }
  26.  
  27. cout << "a^n = " << result << endl;
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
enter a real number a: enter an integer n: a^n = 0