print this : 0,1,1,2,3,5,8,13,21,34,55 in computer qbasic
Answers
Answered by
4
Language :
QBasic
Program:
CLS
a=0
b=1
i=0
INPUT "enter the number of terms you want: ";n
WHILE i<n
c=a
a=b
b=c+a
i=i+1
WEND
Output:
Consider the attachment.
Explanation:
These numbers are part of Fibonacci's sequence.
The next terms is always the sum of last two numbers from the 3rd one on and the first two terms are 0 and 1.
- a,b,i are initialized as 0,1, and 0 respectively.
- Input saves the number of terms in n.
- While loop ensures that only n terms are returned.
- number swapping takes place to return the elements.
Attachment:
Attachments:
Similar questions
Science,
1 month ago
Physics,
1 month ago
Computer Science,
1 month ago
Math,
10 months ago
English,
10 months ago