Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 10-04-2007, 02:43 PM   #1 (permalink)
natelowery
Recruit
 
Join Date: Sep 2007
Posts: 2
natelowery is on a distinguished road
need help with code for Fibonacci numbers

I am trying to write a program that displays the first 10 Fibonacci numbers when executed. The code should look like this:

//Ch7AppE10.cpp – displays the first 10 Fibonacci numbers
//Created/revised by <your name> on <current date>

#include <iostream>

using std::cout;
using std::endl;

int main()
{


return 0;
} //end of main function

It should be done with a "for" statement. Please help.
natelowery is offline   Reply With Quote
Old 10-04-2007, 11:31 PM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,711
redhead is on a distinguished road
Read about Fibonacci numbers, the numbers are derived, by calculating the sum of the two previus numbers ie: 0, 1, 1, 2, 3, 5, 8, ....
Or in mathmatical terms: F(n) = {0, 1, F(n-1) + F(n-2)}

So you would start with a prev number assigned the two static values within this, say prev and cur, and your program would have a structure like:
Code:
10  prev = 0
20  cur = 1
30  print prev
40  print cur
50  temp = prev
60  prev = cur
70  cur = prev + temp
80 if (condition) goto 40
Now you just use that to create your for() loop, but be sure to read up on Fibonacci numbers, you know, half of Comp. Sci. is the math within.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Obfuscation: Complete waste of time? morpheuz PHP 28 08-22-2006 10:20 PM
writing a code of a program that sorts numbers Dina MS Technologies ( ASP, VB, C#, .NET ) 1 10-06-2005 04:33 PM
Perplexing Error on C Code etorres Standard C, C++ 6 03-24-2005 08:16 PM
Cisco Code breaking sde Code Newbie News 0 05-21-2004 07:10 AM


All times are GMT -8. The time now is 09:25 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting