Generate Fibonacci series using Sub Routine

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

14 comments:

  1. can we generate same output using function procedure? If we can please let me know!

    ReplyDelete
  2. generate given series plz
    1 2 3 4 = 10
    5 6 7 8 = 26
    9 10 11 12 = 42
    ------------
    15 18 21 24

    ReplyDelete
    Replies
    1. CLS
      C=1
      S=0
      DO
      PRINT C;
      C=C+1
      S=S+C
      LOOP WHILE C<=4
      PRINT"=";S
      DO
      PRINT C;
      C=C+1
      S=S+C
      LOOP WHILE C<=8
      PRINT "=";S
      ...........
      LIKE WISE

      Delete
  3. Replies
    1. CLS
      FOR I = 1 TO 5
      FOR j = 1 TO I
      PRINT I;
      NEXT j
      PRINT
      NEXT I

      Delete
  4. Replies
    1. This comment has been removed by the author.

      Delete
    2. Declare sub series (A,b)
      Cls
      A=0
      B=9
      Call series (A,B)
      END
      SUB SERIES (A,B)
      FOR I =1 TO 6
      N=9
      PRINT;
      N=(N*10)+9
      NEXT I
      END SUM

      YO PROGRAMMING YESARI GARNE HO 😊😊👍 TAR NUMBER ANUSAR HUNXA 😏

      Delete
  5. How to display acronym???
    robin karki
    Display "robin k"

    ReplyDelete
  6. dear sir can you print fibonacci using function procedure

    ReplyDelete
  7. How to generate fibonacci series in qbasic with while loop

    ReplyDelete
  8. display the fibonacci series (1, 1, 2, 3, 5 upto 10th terms)

    ReplyDelete
  9. WAP to declare sub procedure to display fibonacci series of 1,1,2,3,5,8,.. up to 10 term

    ReplyDelete