limun11

PRII - Faktorijel - rekurzija

Mar 20th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.34 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int faktorijel(int broj)
  5. {
  6.     if (broj <= 1)
  7.         return 1;
  8.     else
  9.         return broj*faktorijel(broj - 1);
  10. }
  11.  
  12. void main()
  13. {
  14.     int broj;
  15.     cout << "Unesite broj od kojeg želite faktorijel: ";
  16.     cin >> broj;
  17.     cout << "Faktorijel unesenog broja je: " << faktorijel(broj) << endl;
  18.     system("PAUSE");
  19. }
Advertisement
Add Comment
Please, Sign In to add comment