Advertisement
tampurus

4 Fibonacci & Factorial

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