+ 2

Need some tricky programs on Recursion.

Programs should be simple to understand.

5th Mar 2017, 1:24 PM
Mohit Khokhar
Mohit Khokhar - avatar
2 Respostas
+ 3
factorial nubers!!!!! n! = n *(n-1)! 5! = 5 * 4 * 3 * 2 * 1. that is equivalent to 5! = 5 * 4! because 4! = 4 * 3 * 2 * 1 int result=0; void factorial(int num){ if (num==1){ break; //condition to avoid multiplying by 1or 0 }else{ result = num*factorial(num-1); //recursion in here } } System.out.println(result);
5th Mar 2017, 8:31 PM
seamiki
seamiki - avatar
+ 1
Take a look at my simple script. https://code.sololearn.com/cXY4itC2b1iq/?ref=app
5th Mar 2017, 1:45 PM
Nikolay Digaev