Answer to Question #240657 in Algorithms for Sonu

Question #240657

A. The Fibonacci numbers are the numbers in the following integer sequence.

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ……..

In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation. 

         Fn = F n-1 + F n-2


B. Factorial of a non-negative integer, is multiplication of all integers smaller than or equal to n. For example, factorial of 6 is 6*5*4*3*2*1 which is 720.

         n! = n * (n - 1) * …….. 1 


 Write the algorithms to display the Fibonacci series and the factorial value for a given number using Pseudo code.


1
Expert's answer
2021-09-22T23:44:51-0400

A.

function printFibonacci(n):
  prevFib = 0
  currFib = 1
  i = 0
  while i <= n:
    print prevFib
    nextFib = prevFib + currFib
    prevFib = currFib
    currFib = nextFib
    i = i + 1

B.

function factorial(n):
  result = 1
  i = 2
  while i <= n:
    result = result * i
    i = i + 1
  return result

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS