473,765 Members | 2,159 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Decimal Value of the Ratios of Consecutive Fibonacci Numbers

4 New Member
Hi

I have been doing this working on an assignment for the last week and have stumbled across a part which I cant get my head around. I was hoping that someone could explain what I am missing. I do not expect you to do my work for me. I have completed the rest of the assignment and I am just stuck here (at the very end). Here is my problem.

"I have to find out the decimal values of the ratios of consecutive fibonacci numbers."

As I said before it is the last part of my program. I had to among other things display the first n fibonacci numbers. I have done a for loop to find the fibonacci number and it displays fine. I was mainly wondering do you use this for loop somehow to find the decimal values or create a new one? Well do you even use a for loop at all? Just not sure where to begin. Have tried for the last couple of days. Even if you could suggest some websites that might help. Any help would be greatly appreciated.
Apr 10 '08 #1
8 3194
Laharl
849 Recognized Expert Contributor
You should store the computed fibonacci numbers into an array so that you don't have to recalc them. Also, a for loop is something that would be useful here.
Apr 10 '08 #2
help2008
4 New Member
Thank you, for your advice, dont really know much about arrays. We havent studied that yet so I am googling it at the moment. Do I need to create a separate for loop or use the one I have for the fibonacci sequence? Also I am not sure exactly how to write it so it divides. This is what the example looks like when it is finished (the parts in bold are what I need to work out). (the other parts seem to work out ok).

Program computes the first n Fibonacci numbers and ratios of
consecutive ones. Enter n: 11
~~~~~~~~~~~~~~~ ~~~~~~~~~
Fibonacci
number Ratio
~~~~~~~~~~~~~~~ ~~~~~~~~~
1
1 1.000000000000
2 0.500000000000
3 0.666666666667
5 0.600000000000
8 0.625000000000
13 0.615384615385
21 0.619047619048
34 0.617647058824
55 0.618181818182
89 0.617977528090
~~~~~~~~~~~~~~~ ~~~~~~~~~

Again, any help would be appreciated.
Apr 10 '08 #3
Laharl
849 Recognized Expert Contributor
Be aware that for accurate (aka decimal) division, you need to use doubles. Also, you'll need a second loop if you use the array, though you can do it in one loop if you store the value of the last computation in a temporary variable (so that you have two available at any given time).
Apr 10 '08 #4
Banfa
9,065 Recognized Expert Moderator Expert
If you have to output the ratio on the same line as the Fibonacci number then a single for loop should work, all you have to do is use a variable to keep track of the last Fibonacci number which you should have anyway in order to calculate the next one

i.e. You are trying to calculate

Fib(n) = Fib(n-1) + Fib(n-2)

and

ration = Fib(n-1)/Fib(n)
Apr 10 '08 #5
JosAH
11,448 Recognized Expert MVP
You can easily find the ratio F(n)/F(n-1) from this nice page.
Start reading at equation (2) on that page.

kind regards,

Jos
Apr 10 '08 #6
help2008
4 New Member
Thank you to everyone for your help. Unfortunately I am more confused now than ever.

I do need to display them on the same line. I cannot understand how to put it into an array. I have not studied this yet and this is my first year. I cannot find anything simple enough for me to understand (I am pretty dumb at this). I have somehow baffled my way through the for loops, still dont really understand how they work. But I am really stuck on how to hold it in an array or even how to write an array. Again every bit of advice is appreciated. Even if it is to tell me I am too dumb for this subject (As I feel that at the moment). As an external student you don t really get any support. Thanks again to everyone for their help.
Apr 11 '08 #7
Banfa
9,065 Recognized Expert Moderator Expert
You don't actually need to use an array all you need to do is hold the last 2 Fibonacci numbers
Apr 11 '08 #8
help2008
4 New Member
Sorry. How do I do that?
Apr 21 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

21
4529
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
17
6149
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number. "Decimal Number" sometimes serves to distinguish Base 10 numbers, eg "15", from Base 2 numbers, Eg "1111". At other times "Decimal Number" serves to differentiate a number from an integer. For the rest of this post I shall only use either...
28
13118
by: dleecurt | last post by:
Hello, I have a small problem, I am trying to write a program that will calculate the Fibonacci number series, and I have the code complete with one problem. I used a long in to store the numbers, and when the numbers get too large it maxes out the int and I can't count any higher. I am trying to use extremely large numbers, I would like to use up to 10^50 or so. So my question is how do I do this? I'm just learning the language and I...
4
4861
by: YS Sze | last post by:
If you know the exact longitude and latitude for a specific location, would anyone think it'd make any sense to find out if this set of location numbers is really part of the Fibonacci series or not? Or, another way to look at this is that: Would anyone of you think it is worth a while to find out if there is any location on earth with the set of longitude and latitude numbers that coincides with the Fibonacci series? As I see it, if...
11
2257
by: Pieter | last post by:
Hi, I'm having some troubles with my numeric-types in my VB.NET 2005 application, together with a SQL Server 2000. - I first used Single in my application, and Decimal in my database. But a Single with value 4.475 was converted to a Decimal with value 4.4749999999999996D. So after inserting and selecting it from the database I got another value than the original!
28
5932
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places? ----------------------------------------------------------------------- When formatting money for example, to format 6.57634 to 6.58, 6.5 to 6.50, and 6 to 6.00? Rounding of x.xx5 is uncertain, as such numbers are not represented exactly. See section 4.7 for Rounding issues.
6
4975
by: Andrew Tatum | last post by:
I'm having some problems with the below equation. I have no problems when it comes to positives. Negatives create the problem.. C 2 1 4 However, this doesn't work:
10
5325
by: Jason | last post by:
I'm making a program that will convert decimal inputs (in this case, in inches) and output a fractional answer. At the moment, I'm only able to output the fractional answer in three parts: A whole number text box, a numerator text box, and a denominator text box. I realize that this is probably the closest I'll get to having fractions displayed in VB, so that's no big deal. I'm able to simplify most numbers with some code I've written,...
0
28067
Frinavale
by: Frinavale | last post by:
Convert a Hex number into a decimal number and a decimal number to Hex number This is a very simple script that converts decimal numbers into hex values and hex values into decimal numbers. The example following this one demonstrates how to convert decimal numbers into binary values. A hex number is a string that contains numbers between 0-9 and characters A-F; where A = 10, B = 11, ..., F = 15. (For more information please look up...
0
9398
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10156
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9951
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2805
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.