
-----------------------------------
kid105
Wed Jan 13, 2010 9:09 pm

im lost can someone help me plzz
-----------------------------------
What is it you are trying to achieve?

1, 1, 2, 3, 5, 8, 13, 21, 34, . . . 
write a program which generates the first n terms of this sequence, where the value of n is entered by the user, given the first two terms of the sequence. cuccessive terms are to be stored in an array.


What is the problem you are having?
im kind of stuck on this one i keep getting errors.


Describe what you have tried to solve this problem
i have written this program below.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)




var number : array 1 .. 10 of int
var sum := 0
put skip
for counter : 1 .. 10
    put "Enter number ", counter, ": " ..
    get number (counter)
end for
put skip
put "The ten numbers in order of entry are: "
put skip
for counter : 1 .. 10
    put number (counter) : 5 ..
end for
for counter : 1 .. 10
    sum := sum + number (counter)
    put sum
end for



Please specify what version of Turing you are using


-----------------------------------
Turing_Gamer
Wed Jan 13, 2010 10:36 pm

Re: im lost can someone help me plzz
-----------------------------------
You may need and intstr command for the following

for counter : 1 .. 10
    put intstr (number (counter))
end for
for counter : 1 .. 10
    sum := sum + number (counter)
    put intstr (sum)
end for

-----------------------------------
Euphoracle
Wed Jan 13, 2010 10:43 pm

RE:im lost can someone help me plzz
-----------------------------------
Well, your code is not solving the problem asked.  You are asked to input one number value from the user (a natural number to be precise) and complete the sequence to that many numbers, we'll call that n.

Now, if you analyze the sequence, you may notice the following pattern:

Consider the sequence carefully,

{1, 1, 2, 3, 5, 8, ...}

You are given the first two numbers (1 and 1).  How can you get 2 from 1 and 1?
How can you get 3 from 1 and 2?
How can you get 5 from 2 and 3?

That's your pattern.

Your program should take as input n which is an int and output this sequence to n terms.

You can generate the next term using the previous two terms using the pattern from above.  You should do this for n terms.
