+ 2
Need some tricky programs on Recursion.
Programs should be simple to understand.
2 Respuestas
+ 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);
+ 1
Take a look at my simple script. https://code.sololearn.com/cXY4itC2b1iq/?ref=app