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
icon
Related questions
Question
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 ("error"); exit();
if (n=0) then print ("Fibonacci number is 0");
exit();
if (n=1) then print ("Fibonacci number is 1");
exit();
1.
2-4.
5-7.
8-10.
11-12. f1=0;
f2=1;
for i = 2 to n do
13.
14-16.
f = f1 + f2;
f1 = f2;
£2 = f;
print("Fibonacci number is", f);
17.
18.
end Fibonacci
end
Transcribed Image Text: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 ("error"); exit(); if (n=0) then print ("Fibonacci number is 0"); exit(); if (n=1) then print ("Fibonacci number is 1"); exit(); 1. 2-4. 5-7. 8-10. 11-12. f1=0; f2=1; for i = 2 to n do 13. 14-16. f = f1 + f2; f1 = f2; £2 = f; print("Fibonacci number is", f); 17. 18. end Fibonacci end
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Computational Systems
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning