neogz

pow(a,n) rekurzija

Apr 1st, 2014
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.30 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. int f(int a, int n)
  6. {  
  7.     if (n == 1) return a;
  8.     else return a*f(a,n - 1);
  9. }
  10.  
  11. int main()
  12. {
  13.     int a,n;
  14.     cout << "a^n \n\nUnesi a: ";
  15.     cin >> a;
  16.  
  17.     cout << "Unesi n: ";
  18.     cin >> n;
  19.  
  20.     cout << "REZULTAT = " << f(a, n);
  21.  
  22.     system("pause >nul");
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment