Internet Programming Lab 2
Internet Programming Lab 2
2. Task to be done:
Write a java program that uses both recursive and non-recursive functions to print the n th value in the
Fibonacci sequence.
3. Algorithm/Flowchart :
Algorithm to generate fibonacci series
First two terms of fibonacci series is 0 and 1.
we will store the last two terms of fibonacci series in "last" and "secondLast" integer variable.
Current term of fibonacci series is equal to the sum of "last" and "secondLast" term.(current = last + secondLast)
Update last and secondLast variable as secondLast = last; and last = current;
4. Dataset:
import java.util.Scanner;
class Main
{
public static void main(String args[])
{
System.out.println("Enter the number n to print the faboniccs series ");
Scanner ob=new Scanner(System.in);
short a=ob.nextShort();
Series ob1=new Series();
long b=ob1.input(a);
System.out.println("The "+a+"th number of the faboniccs series is "+b);
}
}
class Series
{
int a=1;
int b=1;
int c=0;
int count;
int input(int a)
{
count=a;
count=fabo(count);
return count;
}
3. I learnt that what is algorithm to find uses both recursive and non-recursive functions to print
the nth value in the Fibonacci sequence.
4.
5.
Evaluation Grid:
Sr. No. Parameters Marks Obtained Maximum Marks
1. Demonstration and Performance 5
2. Worksheet 10
3. Post Lab Quiz 5