Analyze the behavior of the following program, which computes the nth Fibonacci number, for appropriate values of n. Obtain the frequency count of the statements (that are given line numbers) for various cases of n. 34 A Textbook of Data Structures and Algorithms 1 procedure Fibonacci (n) read (n); if (n<0) then print 1. 2-4. 5-7. ("error"); exit(); if (n=0) then print ("Fibonacci number is 0"); exit(); 8-10. if (n=1) then print ("Fibonacci number is 1"); exit(); 11-12. f1=0; f2=1; for i=2 to n do f = f1 + f2; 13. 14-16. f1 = f2; f2 = £; print("Fibonacci number is", f); end 17. 18. end Fibonacci
Analyze the behavior of the following program, which computes the nth Fibonacci number, for appropriate values of n. Obtain the frequency count of the statements (that are given line numbers) for various cases of n. 34 A Textbook of Data Structures and Algorithms 1 procedure Fibonacci (n) read (n); if (n<0) then print 1. 2-4. 5-7. ("error"); exit(); if (n=0) then print ("Fibonacci number is 0"); exit(); 8-10. if (n=1) then print ("Fibonacci number is 1"); exit(); 11-12. f1=0; f2=1; for i=2 to n do f = f1 + f2; 13. 14-16. f1 = f2; f2 = £; print("Fibonacci number is", f); end 17. 18. end Fibonacci
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 8SA
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning