//How to print the nth number of a Fibonacci series by recursive method
// fibo(5)
// fibo(4) + f ibo(3)
// fibo(3) + f ibo(2) + fibo(2) + fibo(1)
//fibo(2) + fibo(1) + 1 + 1 + 1
// 1 + 1 + 1 + 1 + 1 = 5
import java.io.*;
class factorial
{
public static long getfactorial(int n)
{
if(n<=0)
return 1;
return n * getfactorial(n-1);
}
public static void main(String[] args) throws IOException
{
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
System.out.print("\nEnter number : ");
int n=Integer.parseInt(rd.readLine());
System.out.print("\nFactorial of " + n + " = " + getfactorial(n));
}
}
// fibo(5)
// fibo(4) + f ibo(3)
// fibo(3) + f ibo(2) + fibo(2) + fibo(1)
//fibo(2) + fibo(1) + 1 + 1 + 1
// 1 + 1 + 1 + 1 + 1 = 5
import java.io.*;
class factorial
{
public static long getfactorial(int n)
{
if(n<=0)
return 1;
return n * getfactorial(n-1);
}
public static void main(String[] args) throws IOException
{
BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));
System.out.print("\nEnter number : ");
int n=Integer.parseInt(rd.readLine());
System.out.print("\nFactorial of " + n + " = " + getfactorial(n));
}
}
No comments:
Post a Comment