neogz

2sem- faktorijel silazna rekurzija

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