Coding fibonacci without using fibonacci matlab code

Write a MATLAB program that creates and outputs the first 30 numbers in the Fibonacci series. The Fibonacci series is 0, 1, 1, 2, 3, 5, 8, 13, 21, … The first two numbers are 0 and 1. Each subsequent number is the sum of the two preceding numbers. So, the next number in the example above is 13 + 21 = 34. And the next number is 21 + 34 = 55. And so on. In your code, explicitly assign the first two numbers in the series, then built up the rest of series using a for-loop. Do not use MATLAB's fibonacci function (available in the Symbolic Math Toolbox). We're looking for very specific output in this question. Output the 30 numbers, 5 numbers per line over 6 lines. Use an 8-character field width for each number. One final thing. Create all the output using a single fprintf statement that executes just once

And here is the code I've written so far. I need help getting the format of the code, and just clarifying that I did the right thing?

Direct link to this answer

Hint: The fprintf( ) function will automatically wrap around if you have too many variables than the format string allows for. E.g., If I try to print four numbers using a string that only prints two numbers (each to a 5 digit field) with a newline at the end I will get this result:

>> fprintf('%5d%5d\n',1:4)

1 2

3 4

Modify that to get the result in the format you want for your specific case.

This website uses cookies to improve your user experience, personalize content and ads, and analyze website traffic. By continuing to use this website, you consent to our use of cookies. Please see our Privacy Policy to learn more about cookies and how to change your settings.