Computer Science, asked by triggerAVS3819, 1 year ago

Write a MARIE program to calculate Fib(n), where the user inputs n. For example, if the user inputs 7, the program outputs the value 13; if the user inputs 15, the program outputs the value 610; if the user inputs 20, the program outputs the value 6765 and so on. You need to write and run the program using MARIE simulator. Please include appropriate comments to make your code readable.[8 marks]

Answers

Answered by sailorking
1

The program is written in java:-

import java.io.*;

class fibonacci

{

        public static void main(String args[])throws IOException

         {

            Buffered Reader in=new Buffered Reader (new Inut Stream Reader ( System . in ) );

             System . out . println (" Enter the number ");

              int n=Integer. parse Int ( in. readLine);

               int a = 1, b = 1;

               int sum=0;

                for( int i=0 ; i<=n; i++)

                 {

                      sum =a+b;

                      System .out. println ( sum );

                       a = b;

                        b = sum;

                     }

            }

}

Answered by Sidyandex
0

Answer:

In this example, it will set with Fibonacci sequence and includes while loop in the given input.

It should undergo to say in the nth term and sum of (n-1)th and (n-2)th term.

Fibonacci factors are then calculated and bring it to take input from the user n terms.

This is associated with readline and number of terms includes more than 2.

Similar questions