Saturday , 5 December 2020
Home » Class 12 » [Question 12] ISC 2005 Solved (Fibonacci Series Using Recursion)

[Question 12] ISC 2005 Solved (Fibonacci Series Using Recursion)

Question:

A class Fibonacci_Recursion has been defined to find the Fibonacci series upto a limit. Some of the members of the class are given below:

Class Name : Fibonacci_Recursion

Data Members/instance variables : a, b, c, limit (all integers)

Member functions/methods :

Recursion() : constructor to assign a,b,c with appropriate values.
void input() : to accept the limit of the series.
int fib(int n) : to return the nth Fibonacci term using recursive technique.
void genearate_fibseries() : to generate the Fibonacci series upto the given limit.

Specify the class Fibonacci_Recursion giving details of the constructor, int fib() , void generate_fibseries(). You may assume other functions are written for you and you need not write the main function.


Programming Code:

/**
* The class Fibonacci_Recursion prints the Fibonacci Series upto ‘n’ terms using the concept of Recursion
* @author : www.guideforschool.com
* @Program Type : BlueJ Program – Java
* @Question Year : ISC Theory 2005 Question 12
*/

import java.util.*;
class Fibonacci_Recursion
{
    int a,b,c,limit;
    Fibonacci_Recursion()
    {
        a=0;
        b=1;
        c=0;
        limit=0;
    }

    void input()
    {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the limit : ");
        limit = sc.nextInt();
    }

    int fib(int n)
    {
        if(n<=1)
            return a;
        else if(n==2)
            return b;
        else
            return (fib(n-1)+fib(n-2));
    }

    void generate_fibseries()
    {
        System.out.println("The Fibonacci Series is:");
        for(int i=1;i<=limit;i++)
        {
            c=fib(i);
            System.out.print(c+"  ");
        }
    }

    public static void main(String args[])
    {
        Fibonacci_Recursion ob = new Fibonacci_Recursion();
        ob.input();  
        ob.generate_fibseries();
    }
}

Output:

Enter the limit : 11
The Fibonacci Series is:
0 1 1 2 3 5 8 13 21 34 55

Enter the limit : 20
The Fibonacci Series is:
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181

Check Also

[Question 1] ISC 2019 Computer Practical Paper Solved – Future Date

Solution of Program 1 of ISC 2019 Computer Science Paper 2 (Practical) Exam. Java program to find the future date.

5 comments

  1. nice program…

  2. can you please write the programs for factorial and gcd of a number using recursion

  3. Sanjeev Saniel

    I am very much glad as I have got maximum answers from this websites regarding programs.

  4. Sanjeev Saniel Kujur

    I am very happy to visit this website and get the answers.

Leave a Reply

Your email address will not be published. Required fields are marked *