FIBONACCI SERIES: find the Fibonacci series of the give number using sql program


Get the no of terms n in the Fibonacci series to be generated.
If n is less than 2 then raise an exception on display the message.
Otherwise initialize the value of a as 0 and b as 1 and display them.
Concatenate the extract character.
Repeat the step5 and step6 in n-3 times.
C=a+b and display c.
A=b and b=a.
Stop the program.

SQL> set serveroutput on
SQL> declare
2 a number(3);
3 b number(3);
4 c number(3);
5 n number(3):=&n;
6 negative exception;
7 begin
8 if n<2 then
9 raise negative;
10 end if;
11 a:=0;
12 b:=1;
13 dbms_output.put_line('fibonacci series is');
14 dbms_output.put_line(a);
15 dbms_output.put_line(b);
16 for i in 3..n
17 loop
18 c:=a+b;
19 dbms_output.put_line(c);
20 a:=b;
21 b:=c;
22 end loop;
23 exception
24 when negative then
25 dbms_output.put_line('N should be greater than 1');
26 end;
27 /

No comments:
Write comments