Question

Write a SQL Program to print out the first 10 numbers of the following sequence F(n)....

Write a SQL Program to print out the first 10 numbers of the following sequence F(n).

F(1) = 3, F(2)=5. F(n)=3*F(n-1) –2*F(n-2).

E.g., F(3) = 3*F(2) – 2* F(1) = 3*5–2*3=15-6=9

Your program will print out F(1), F(2),..., F(10).

Hint: use three variables, the first storing F(n), the second storing F(n-1), and the third storing F(n-2). Think of how to compute the first variable from the other two and how to update the other two variables in each iteration

0 0
Add a comment Improve this question Transcribed image text
Answer #1

declare

-- declare variable first = 3,
-- second = 5 and temp of datatype number
first number := 3;
second number := 5;
temp number;

n number := 10;
i number;

begin

   dbms_output.put_line('Series:');

--print first two term first and second
   dbms_output.put_line(first);
   dbms_output.put_line(second);

-- loop i = 2 to n
   for i in 2..n
   loop
       temp:=3*second-2*first;

first := second;
second := temp;

--print terms of fibonacci series
   dbms_output.put_line(temp);
end loop;

end;
--Program End

Add a comment
Know the answer?
Add Answer to:
Write a SQL Program to print out the first 10 numbers of the following sequence F(n)....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT