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
  • The sequence of the first twelve Lucas numbers is: 2,1,3,4,7,11,18,29,47 … Please write a program for...

    The sequence of the first twelve Lucas numbers is: 2,1,3,4,7,11,18,29,47 … Please write a program for calculating the Lucas number Ln given the number n. Print out the results given: a) n=2 ; b) n=5 and c) n=10 (**please answer in Python**) Ln 2 1 (Ln-1 + Ln-2 if n= 0 if n = 1 if n >1

  • In Python! Create the program that print out only odd numbers 1,3,5,7,9 Use either a while...

    In Python! Create the program that print out only odd numbers 1,3,5,7,9 Use either a while loop or a for loop to print only odd numbers 1, 3, 5, 7, 9 *tip: you can use range () function, or a condition with ‘break’ (e.g, while count < 10) In python!: Create a program that print out 12 months of a year and associated numbers (e.g., January 1, February 2…). Two lists should be created, and then loop through the list...

  • Write a program that generates 2n Fibinacci numbers. the following is a sequence of Fibinacci numbers:...

    Write a program that generates 2n Fibinacci numbers. the following is a sequence of Fibinacci numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89... (Starting from the third number, the number is the sum of the previous two numbers.)

  • Please answere using python language codes. Write a program to print out Collatz sequence for a...

    Please answere using python language codes. Write a program to print out Collatz sequence for a user-supplied number. Prompt the user for a positive integer which will become the first number in the sequence. Next number in the sequence is derived as follows: If previous number is odd, the next number is 3 times the previous, plus 1. If previous number is even, the next number is half of the previous According to Collatz proposition, the sequence ultimately reaches 1...

  • Write a java program that will print if n numbers that the user will input are...

    Write a java program that will print if n numbers that the user will input are or not within a range of numbers. For that, your program needs to ask first for an integer number called N that will represent the number of times that will ask for other integer numbers. Right after, it should ask for two numbers that will represent the Min and Max for a range. Lastly. it will iterate N number times asking for an integer...

  • Write a complete C program that generate the following sequence of numbers in two ways. First,...

    Write a complete C program that generate the following sequence of numbers in two ways. First, the sequence of numbers should be made using a WHILE LOOP, then a DO-WHILE LOOP. 19, 15, 11, 7, 3, -1, -5, -9

  • The Fibonacci sequence is the sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13,...

    The Fibonacci sequence is the sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, … The next number is found by adding up the two numbers before it. For example, the 2 is found by adding the two numbers before it (1+1). The 3 is found by adding the two numbers before it (1+2). The 5 is found by adding the two numbers before it (2+3), and so on! Each number in the sequence is called...

  • A Fibonacci sequence is a series of numbers where the next number in the series is...

    A Fibonacci sequence is a series of numbers where the next number in the series is the sum of the previous two numbers. The sequence starts with the numbers 0 and 1. Here are the first ten numbers of the Fibonacci sequence:             0 1 1 2 3 5 8 13 21 34 Write a Java program to print out the first fifteen numbers of the Fibonacci sequence using a loop. You will need three variables previous, current, and next...

  • Can someone help me with this PHP code thank you in advance!! Write a PHP program...

    Can someone help me with this PHP code thank you in advance!! Write a PHP program to print the first 10 terms of a Fibonacci sequence. You need to use arrays to store and print the terms. In the Fibonacci sequence, the next number is found by adding up the two numbers before it. The Fibonacci Sequence starts with 0 and 1 as the first two terms. So F[0]=0 and F[1]=1 and the series propagates such that F[n]= F[n-1]+F[n-2]. The...

  • Write a Python program (using a nested loop) to print out the following pattern (there is...

    Write a Python program (using a nested loop) to print out the following pattern (there is a space between the numbers next to each other). 1 2 1 3 2 1 4 3 2 1 5 4 3 2 1

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