Advertisement
katarinaknobel

Rekursion

Oct 5th, 2017
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 0.62 KB | None | 0 0
  1. rekursiv definition:
  2. N! = N*(N-1)!
  3.  
  4. N fakultet
  5. 3!=1*2*3=6 etc
  6. 0!=1
  7.  
  8. N!=N*(N-1)!
  9. 4=4* 4-1= 24
  10. 1 om N=0
  11.  
  12. N!
  13.  
  14. Res: Integer; N: Integer; begin
  15. Get(N);     N:3 Res:= Factorial(N)/6;
  16.  
  17. Put (Res);
  18.  
  19. ------------------------------------
  20.  
  21. UP
  22. Function Factorial(    N   :in Integer) (-är ej samma N som tidigare)
  23.             Return integer is
  24.  
  25. Begin
  26. If N=0 then
  27.     Return 1;
  28.     else
  29.         Return N* Factorial(N-1);
  30.     End if;
  31. End Factorial;
  32.  
  33. -----------------------------------
  34.  
  35. function Factorial2( : in Integer) return Integer is
  36.  
  37. begin
  38. if N = 0 then
  39. return 1
  40. else
  41. return N*Factorial(N-1);
  42. end if;
  43. end Factorial2;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement