class FactorialRecusionProgramExample{
static int facto(int a){
if (a == 0)
return 1;
else
return(a * facto(a-1));
}
public static void main(String args[]){
int i,f=1;
int num=5;//Number for which we are calculating factorial
f = facto(num);
System.out.println("Factorial of "+num+" is: "+f);
}
}
static int facto(int a){
if (a == 0)
return 1;
else
return(a * facto(a-1));
}
public static void main(String args[]){
int i,f=1;
int num=5;//Number for which we are calculating factorial
f = facto(num);
System.out.println("Factorial of "+num+" is: "+f);
}
}
No comments:
Post a Comment