Advertisement
Kyrexar

Factorial

Feb 7th, 2013
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.35 KB | None | 0 0
  1. public class factorial
  2. {
  3.     public static int recursivo ( int n )
  4.     {
  5.         if( n<0 ) return 0;
  6.         if( n<=1 ) return 1;
  7.         return n*recursivo(n-1);
  8.     }
  9.  
  10.     public static int iterativo ( int n )
  11.     {
  12.         if( n<0 ) return 0;
  13.         if( n==0 ) return 1;
  14.         for( int i=n-1 ; i>=2 ; i-- ) n*=i;
  15.         return n;
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement