Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class factorial
- {
- public static int recursivo ( int n )
- {
- if( n<0 ) return 0;
- if( n<=1 ) return 1;
- return n*recursivo(n-1);
- }
- public static int iterativo ( int n )
- {
- if( n<0 ) return 0;
- if( n==0 ) return 1;
- for( int i=n-1 ; i>=2 ; i-- ) n*=i;
- return n;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement