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.
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
Comments
Leave a comment