FIBONACCI SERIES

AIM:
    To find the Fibonacci series of the give number using sql program.

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

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 /
Previous
Next Post »

If you still didn't find what you're looking for, you can search this website below: