Write a program to calculate the Fibonacci number, not exceeding the predetermined number N
Fibonacci numbers are calculated using the following relations: F0 = 0; F1 = 1; Fi = Fi-1 + Fi-2 для i > 1
F0 = 0; F1 = 1; Fi = Fi-1 + Fi-2 для i > 1
Sub Main() Dim f1&, f2&, N& f1 = f2 = 1 N = 20 While f1 <= N f1 = f1 + f2 f2 = f1 - f2 End While MsgBox f2 End Sub
For some reason, when executing this code, Excel hangs tight. I would be very grateful if you tell me what the error is so that I will not commit it in the future.
PS I can write this program in any other language, but VBA doesn’t give me anything.