Question: The Fibonacci sequence is a sequence of numbers such that the first two numbers are 0 and 1, and each successive number is the sum

The Fibonacci sequence is a sequence of numbers such that the first two numbers are 0 and 1, and each successive number is the sum of the two previous numbers. Thus, here are the first nine numbers in the Fibonacci sequence:

0 1 1 2 3 5 8 13 21 

The third number is 1 because the previous two numbers, 0 and 1, add up to 1. The fourth number is 2 because the previous two numbers, 1 and 1, add up to 2.

Provide a code fragment that prints the Fibonacci sequence numbers for the numbers less than 25 (i.e., the numbers shown above). Your code fragment must consist of just a for loop header terminated by a semicolon—nothing else. Use comma-separated initialization and update components. Feel free to use the following as a start for your for loop:

for (int m=0, n=1, temp;

By the way, we recommend that you avoid using code like this for your real programs. This exercise is just for fun (fun for a hacker, anyway ).

Step by Step Solution

3.41 Rating (148 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

for int m 0 n 1 temp m 25 temp m m n n temp Heres the completed for ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Introduction To Programming With Java A Problem Solving Approach Questions!