Welcome to WebmasterWorld Guest from 54.197.65.97 register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts, Become a Pro Member
 Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

 Tweet
display fibonacci sequence on web page
really stuck
gunter

Msg#: 3939296 posted 8:04 am on Jun 24, 2009 (gmt 0)

Can anyone please write, solve the program for displaying the following on a web page.

The first 20 elements of the fibonacci sequence are,
1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765
9 ratios were needed
the final ratio was:1.6176470588235294
the golden ratio is:1.61803399
the final difference was:0.00038693117647059516

the program must be written with the following information.
first write the function called difference() that will take two numbers as arguments and return the difference between them.
Then generate the first 20 numbers for the fibonacci sequence and store them in an array called fibonacciArray.
Then it should calculate the ratio by dividing each element with the one before it and store these values in a second parrallel array called ratioArray.
It should then find the first value of ratioArray that is closer to the golden ratio than 0.0001m byt 1.61803399 will be used as the value for the golden ratio.
finally it should display output in browser similar to what is above.
thankyou very much, any help will be greatly appreciated

whoisgregg

Msg#: 3939296 posted 6:46 pm on Jun 25, 2009 (gmt 0)

Welcome to WebmasterWorld, gunter!

We'd be happy to help you troubleshoot code you've already started. We are all volunteers here, so we rarely have time to write complete scripts for other people.

However, if you do get the code started and post what you've got, I'm sure we'll be able to help. :)

gunter

Msg#: 3939296 posted 7:28 pm on Jun 25, 2009 (gmt 0)

this is what i have tried so far, but nothing happens.

<html>

<title></title>

<body>
function difference()
{
{document.write('difference' + '/' + '<BR>');
}

var fibArray(20);

int i, fib[20]#include<stdio.h>

int main() {

fib[1}= 0;

fib[1] = 1;
{
for (i = 2; i < 10; i++) {fib[i] = fib[i - 1] + fib[i - 2];
}
printf("The fibonacci series is as follows \n");
for (i = 0; i < 10; i++) {

printf("%d \n", fib[i]);

}
return 0;

}

</body>

</html>

birdbrain

Msg#: 3939296 posted 9:25 pm on Jun 25, 2009 (gmt 0)

Hi there gunter,

I do have a fibonacci sequence generator, that I coded, on my pc, would that help you in your project?

bidbrain

pinterface

Msg#: 3939296 posted 10:09 pm on Jun 25, 2009 (gmt 0)

Your code there has a mix of HTML, JavaScript, and C--not one of which is correct. That's a fairly significant misunderstanding which is almost certainly best solved by finding your instructor and asking for help.

It's okay! That's what instructors are for!

If you don't want to ask your instructor--or your instructor is not particularly helpful--you could also try searching the web for [javascript tutorial] or looking for beginner-level JavaScript books at your local bookstore or library.

gunter

Msg#: 3939296 posted 5:32 am on Jun 26, 2009 (gmt 0)

that would be great birdbrain, thankyou.

i have tried again, is this any improvemt, though, it still don`t work lol.

<HTML>
<TITLE>Fibonnaci Sequence
</TITLE>
<SCRIPT>

/************************* Function definition *************************/
function return;
function difference();
{
document.write('take < number' / 'by > number','');
}

var fibonacciArray = [];
var ratioArray = [];

var firstnumber = 1, secondnumber = 1, thirdnumber = 0;

while (thirdnumber < 20000)
{
thirdnumber = firstnumber + secondnumber;
if (thirdnumber < 20000)
{
return(thirdnumber);
}
firstnumber = secondnumber;
secondnumber = thirdnumber;
}

</SCRIPT>
<BODY>
</BODY>
</HTML>

birdbrain

Msg#: 3939296 posted 6:39 am on Jun 26, 2009 (gmt 0)

Hi there gunter,

here is my little fibonacci sequence generator...

 `fibonacci numbers

fibonacci sequence

```

Note:-
You must replace all instances of the broken vertical line -
¦ with a solid vertical line.