Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

PRACTICAL WORKSHEET – 2

STUDENT’S NAME – ANANYA SINGH

STUDENT’S UID – 20BCS4585

CLASS AND GROUP – 20IBIT-1_B

SEMESTER – 3

AIM– Write a program to print implement


A. FIBONACCI SERIES (WITHOUT RECURSION)
B. FIBONACCI SERIES (WITH RECURSION)

ALGORITHM:

Step 1:Set a=0,b=1,c=0


Step 2: Read size
Step 3: Print a,b
Step 4: Repeat through step-8 until (c < = size)
Step 5: c=a+b
Step 6: If (c < =size) then print c
Step 7: Set a=b
Step 8: Set b=c
Step 9: Exit

SUBJECT NAME –Programming in JAVA SUBJECT CODE-20CSP-235 Lab


PROGRAM CODE-

FIBONACCI SERIES (WITHOUT RECURSION)

import java.util.Scanner;

public class Fib {

public static void main(String args[])


{

Scanner input = new Scanner(System.in);


int t1=0, t2=1,nextTerm=0,n;

System.out.println("Enter the number of terms:");


n=input.nextInt();

System.out.println();

System.out.print(t1);
System.out.print(" "+ t2);

for(int i=2;i<n;i++)
{
nextTerm=t1+t2;
t1=t2;
t2=nextTerm;

System.out.print(" " + nextTerm);


}
}
}

FIBONACCI SERIES (WITH RECURSION)

public class FibR


{
public static void main(String[] args)
{
int value=0;
for (int i=1;i<=10;i++)
{
value= fib(i);
System.out.println(value);
}
}

static int fib(int pos)

SUBJECT NAME –Programming in JAVA SUBJECT CODE-20CSP-235 Lab


{
if(pos==1)

{
return 0;
}
else if (pos==2)
{
return 1;
}
else
{
return fib(pos-1)+fib(pos-2);
}
}
}

ERRORS ENCOUNTERED DURING PROGRAM’S EXECUTION:


(Kindly jot down the compile time errors encountered)

NO ERROR EXECUTED

OUTPUT:

FIBONACCI SERIES (WITHOUT RECURSION)

SUBJECT NAME –Programming in JAVA SUBJECT CODE-20CSP-235 Lab


FIBONACCI SERIES (WITH RECURSION)

LEARNING OUTCOME:

• Identify situations where computational methods would be useful.

• Approach the programming tasks using techniques learnt and write


pseudocode.
• Choose the right data representation formats based on the
requirements of the problem.
• Use the comparisons and limitations of the various programming
constructs and choose the right one for the task.

SUBJECT NAME –Programming in JAVA SUBJECT CODE-20CSP-235 Lab


EVALUATION COLUMN (To be filled by concerned faculty only):

Sr. No. Parameters Maximum Marks


Marks Obtained

1. Worksheet Completion including 10


writing learning objective/ Outcome
2. Post Lab Quiz Result 5

3. Student engagement in Simulation/ 5

Performance/ Pre-Lab Questions


4. Total Marks 20

SUBJECT NAME –Programming in JAVA SUBJECT CODE-20CSP-235 Lab


SUBJECT NAME –Programming in JAVA SUBJECT CODE-20CSP-235 Lab

You might also like