Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import java.math.BigInteger;
- public class Test {
- public static void main(String[] args) {
- new Test().run();
- }
- void run(){
- System.out.println("normal factorial: " +fact(50));
- System.out.println("tail factorial: " +fact_tail(1, 50));
- public long fact_tail(long product, long target ){
- if (target == 1) return product;
- return fact_tail(product* target, target - 1);
- }
- public long fact(int n){
- if (n < 1) return n;
- return n* fact(n-1);
- }
- }
Add Comment
Please, Sign In to add comment