Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Q 8,9
- import java.util.Scanner;
- public class Main{
- static int fact(int n){
- if (n<=0)return 1;
- return n*fact(n-1);
- }
- static int fibo(int n){
- if(n<=2)return n;
- return fibo(n-1)+fibo(n-2);
- }
- public static void main (String args[]){
- Scanner fn = new Scanner(System.in);
- int n;
- n = fn.nextInt();
- System.out.println("Factorial of "+n+" is "+fact(n)+" And "+n+"th term of fibbonaci is "+fibo(n));
- }
- }
- /*
- Factorial of 5 is 120 And 5th term of fibbonaci is 8
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement