Advertisement
makispaiktis

power

Apr 3rd, 2018 (edited)
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. /* Πρόγραμμα 4. Χρήση της Εντολής return ως εντολή ελέγχου. */
  2.  
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int power(int base, int exp)
  8. {
  9.     int result=1;
  10.  
  11.     for(int i=1; i<=exp; i++){
  12.  
  13.         result*=base;
  14.     }
  15.     return result;
  16.  
  17. }
  18.  
  19. int main()
  20. {
  21.     cout << "Give me the base." << endl;
  22.     int a;
  23.     cin >>a;
  24.  
  25.     cout << "Give me the exponent." << endl;
  26.     int b;
  27.     cin >> b;
  28.  
  29.     cout << "The result of " << a << "^" << b << " is: " << power(a,b) << " ." << endl;
  30.  
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement