Write a PL/SQL program to find greatest of three numbers and print Fibonacci series up the largest number found.
DECLARE
--initialize three numbers to check the greatest number
num_one number := 5;
num_two number := 7;
num_three number := 2;
greatest_num number;
--declare variables to find fibonacci series
ft number := 0;
sd number := 1;
temp number;
n number;
i number;
BEGIN
--find the greatest number
IF num_one > num_two
AND num_one > num_three THEN
greatest_num :=num_one;
ELSIF num_two > num_one
AND num_two > num_one THEN
greatest_num :=num_two;
ELSE
greatest_num :=num_three;
END IF;
--end if condition
n :=greatest_num;
dbms_output.put_line('Fibonacci Series:');
--print the first and second numbers
dbms_output.put_line(ft);
dbms_output.put_line(sd);
-- loop i = 2 to n
for i in 2..n
loop
temp:=ft+sd;
ft := sd;
sd := temp;
--print terms of fibonacci series
dbms_output.put_line(temp);
end loop;
END;
--End program
Comments
Leave a comment