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

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

Question:

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

Class Name : 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 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 Recursion prints the Fibonacci Series upto 'n' terms using the concept of Recursion
* @author : www.javaforschool.com
* @Program Type : BlueJ Program - Java
* @Question Year : ISC Theory 2005 Question 12
*/

import java.io.*;
class Recursion
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    int a,b,c,limit;
Recursion() //Constructor
    {
     a=0;
     b=1;
     c=0;
     limit=0;
    }

void input()throws IOException //Function to input the limit
    {
     System.out.print("Enter the limit : ");
     limit=Integer.parseInt(br.readLine());
    }

int fib(int n) //Recursive function generating the 'nth' term of Fibonacci Series
    {
    if(n<=1)
    return a;
    else if(n==2)
    return b;
    else
    return (fib(n-1)+fib(n-2));
    }

void generate_fibseries() //Function generating all the Fibonacci Series numbers upto 'n' terms
    {
        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[])throws IOException
  {
   Recursion ob=new 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 2] ISC 2017 Computer Practical Paper Solved – Quiz Result

Solution of Program 2 of ISC 2017 Computer Science Paper 2 (Practical) Exam. Java program to input the answers of each participant row-wise and calculate their marks

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 to radha Cancel reply

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