rem prints fibonacci series

cls
a=2
b=1
for p = 1 to 5
print a
print b
a=a + b
b=b + a
next p
end

I have done this program. How do you do it using modular programming.. FUNCTION...END FUNCTION???? I tried but it didn't work

google is your friend. Use it.

http://www.schoolfreeware.com/QBasic_Tutorial_38_-_Making_A_Function_-_QB64.html

^

|
What that guy said.

thanks steve sir

To achieve the Fibonacci series using modular programming and functions, you can create a function called "fibonacci" that takes the number of terms in the series as a parameter and returns the resulting series. Here's an example of how you can implement it in a modular way using functions:

```
FUNCTION fibonacci(n)
DIM series(n)
series(0) = 0
series(1) = 1

FOR i = 2 TO n
series(i) = series(i - 1) + series(i - 2)
NEXT i

RETURN series
END FUNCTION

CLS

n = 5
fibSeries = fibonacci(n)

FOR i = 0 TO n
PRINT fibSeries(i)
NEXT i
```

In the above code:

1. The `fibonacci` function takes an integer `n` as a parameter representing the number of terms in the series.
2. A dynamic array `series` of size `n` is created to store the Fibonacci series.
3. The first two elements of the series (`series(0)` and `series(1)`) are initialized with 0 and 1, respectively.
4. A loop iterates from index 2 to `n`, calculating each Fibonacci number as the sum of the previous two numbers and storing it in the `series`.
5. The `series` array is returned at the end of the function.
6. The `CLS` command clears the output screen.
7. The `n` variable holds the number of terms desired in the series, here set to 5.
8. The Fibonacci series is calculated by calling the `fibonacci` function and passing `n` as a parameter. The resulting series is stored in the `fibSeries` array.
9. Finally, a loop iterates over the `fibSeries` array and prints each term of the Fibonacci series.

Make sure to check the syntax and ensure proper code indentation as per the programming language you are using when implementing this code snippet.