Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!

# Another problem.

Stephen Foy
Ranch Hand
Posts: 143

1)The original problem that the Italian mathematician Leonardo Pisano Fibonacci investigated in the year 1202 was about how fast rabbits could breed in ideal circumstances. Suppose a newly-born pair of rabbits, one male, one female, are put in a field. Rabbits are able to mate at the age of one month so that at the end of its second month a female can produce another pair of rabbits. Suppose that our rabbits never die and that the female always produces one new pair (one male, one female) every month from the second month on. The puzzle that Fibonacci posed was...How many pairs will there be in one year?
�At the end of the first month, they mate, but there is still one only 1 pair.
�At the end of the second month the female produces a new pair, so now there are 2 pairs of rabbits in the field.
�At the end of the third month, the original female produces a second pair, making 3 pairs in all in the field.
�At the end of the fourth month, the original female has produced yet another new pair, the female born two months ago produces her first pair also, making 5 pairs, etc.
a)Write a program that outputs the number of pairs of rabbits after 12 months.
b)Now change your program so that it outputs the number of pairs of rabbits for any number of months specified by a user.

Now i have everything coded out, but is there a way in which i can take the value last calculated and add it together with the next value in the set.

As it is, 1, 1, 2, 3, 5, 8, 13. 1+1 = 2 2+3 = 5 and so on.

Any suggestions on how i can achieve this?

Ulf Dittmer
Rancher
Posts: 42967
73
This looks like homework. You need to show us what you have coded so far; otherwise we might get the impression that you're tyring to get us to do your homewokr for you.

marc weber
Sheriff
Posts: 11343
Originally posted by ste fing:
... Now i have everything coded out, but is there a way in which i can take the value last calculated and add it together with the next value in the set...

How do you have this coded now?

Stephen Foy
Ranch Hand
Posts: 143

Got it.
[ October 18, 2005: Message edited by: ste fing ]

marc weber
Sheriff
Posts: 11343
Originally posted by ste fing:
[CODE]... Got it.

Cool.