Site icon Pathshala Nepal

fibonacci series using QBasic Programming

WAP to print fibonacci series upto nth terms using sub .... end sub.


1 Answer


REM a, b, n parameters represents first term, second term and number of terms respectively
DECLARE SUB fibo(a, b, n)
CLS
INPUT "First Term="; x
INPUT "Second Term=";y
REM label number is for data validation that length of terms must be less or equal to 20
10:
INPUT "How many terms="; z
IF z>20 THEN 10
CALL fibo(x, y, z)
END

SUB fibo(a, b, n)
PRINT a, b,
REM first two terms are already printed so started from 3
FOR I = 3 to n
  s=a+b
  PRINT s,
  a=b
  b=s
NEXT I
END SUB

Topics from Computer
Related Questions