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

File Uploading in PHP

  File Uploading in PHP PHP allow you to upload any type of a file i.e. image, binary or text files.etc..,PHP has one in built global variab...