Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Ricorsiva
- {
- public static double fattoriale(double n)
- {
- //5! = 5*4*3*2*1
- if(n==1)
- {
- return 1;
- }
- else
- {
- return n * fattoriale(n-1);
- }
- }
- public static int fibonacci(int n)
- {
- //0,1,1,2,3,5,8,13,21,34
- if(n==1)
- {
- return 0;
- }
- if(n==2)
- {
- return 1;
- }
- return fibonacci(n-1) + fibonacci(n-2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement