Fibonacci number

Reply

Join Date: Oct 2005
Posts: 1
Reputation: morgan_morgen is an unknown quantity at this point 
Solved Threads: 0
morgan_morgen morgan_morgen is offline Offline
Newbie Poster

Fibonacci number

 
0
  #1
Oct 12th, 2005
Hi!
I want to write a program to calculate Fibonacci number NON-RECURSIVE
I tried many times but I could not get the result(0-1-1-2-3-5-8...).
Please help me.
  1. #include <stdio.h>
  2. unsigned int f(int n) {
  3. int i;
  4. unsigned int last=0,current=1;
  5. int result;
  6.  
  7. for(i=1; i<=n; i++) {
  8. last+=current;
  9. //????????
  10.  
  11. printf("-%d",last);
  12.  
  13. }
  14. return last;
  15. }
  16. void f_print(int n) {
  17. printf("%d\n",n,f(n));
  18. }
  19. int main(void) {
  20. f_print(10);
  21. return 0;
  22. }
Reply With Quote Quick reply to this message  
Join Date: Nov 2003
Posts: 360
Reputation: Gary King will become famous soon enough Gary King will become famous soon enough 
Solved Threads: 5
Team Colleague
Gary King's Avatar
Gary King Gary King is offline Offline
PHP/vBulletin Guru

Re: Fibonacci number

 
0
  #2
Oct 12th, 2005
Code: http://www.google.com/search?num=30&...2B&btnG=Search

They all do the same thing. So I'm sure you can just pick one and use that. Or, compare it with yours to see what you did wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC