Advertisement
tampurus

1 Factorial and Fibonacci

Mar 14th, 2022 (edited)
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.41 KB | None | 0 0
  1. import java.util.Scanner;
  2. class raju{
  3.     static int fact(int n){
  4.         if (n<=0)return 1;
  5.         return n*fact(n-1);
  6.     }
  7.     static int fibo(int n){
  8.         if(n<=2)return n;
  9.         return fibo(n-1)+fibo(n-2);
  10.     }
  11.     public static void main (String args[]){
  12.         Scanner fn = new Scanner(System.in);
  13.         int n;
  14.         n = fn.nextInt();
  15.         System.out.println("Factorial of "+n+" is "+fact(n)+" And "+n+"th term of fibbonaci is "+fibo(n));
  16.  
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement