NPTEL » Programming In Java Week 3 : Programming Assignment 1 Aug 2022

 

Week 3 : Programming Assignment 1

Due on 2022-08-18, 23:59 IST

This program is related to the generation of Fibonacci numbers.

For example: 0,1, 1,2, 3,5, 8, 13,… is a Fibonacci sequence where 13 is the 8th Fibonacci number.

A partial code is given and you have to complete the code as per the instruction given below.

import java.util.Scanner;

public class Fibonacci {


public static void main(String args[]){

Scanner sc = new Scanner(System.in);

int n=sc.nextInt();

    System.out.println(fib(n));

}

//Template code:

static int fib(int n) {

    if (n==1)      //Terminal condition

    return 0;

    else if(n==2)

    return 1;

    return fib(n - 1) + fib(n - 2); //Recursive call of function

    }

}







No comments

NPTEL » Programming in Java Week 07 : Programming Assignment 1 2 3 4 and 5

  Week 07 : Programming Assignment 1 Due on 2024-09-12, 23:59 IST Write a Java program to find longest word in given input. Select the Langu...