Help with my fibonacci sequence code
Afficher commentaires plus anciens
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... (add previous two numbers together for the next in the sequence)
1. Use a for-end statement to find the 100th number in the sequence.
2. Update this script using a while statement to find the first number in the sequence that has six digits.
============================================================
This is my code until now.
% fibonacci
a=0; b=1; n=input('Enter no, of terms: ');
for i=1:n fprintf('%d',a); fprintf('\t') c=a+b; a=b; b=c;
end
I'm not sure if is correct. But the assignment require to find the 100th number with a for-end and the other part is to find the sequence that has six digits.
2 commentaires
Abhishek
le 26 Jan 2023
it is correct
John D'Errico
le 26 Jan 2023
@Abhishek - actually, it is not correct. It does not solve the assignment. And while it does appear to compute Fibonacci numbers, the code does not do what was required.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!