944,061 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 3623
  • C RSS
Oct 12th, 2005
0

Fibonacci number

Expand Post »
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. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
morgan_morgen is offline Offline
1 posts
since Oct 2005
Oct 12th, 2005
0

Re: Fibonacci number

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.
Team Colleague
Reputation Points: 53
Solved Threads: 5
PHP/vBulletin Guru
Gary King is offline Offline
360 posts
since Nov 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Accessing To A Struct With A Given Pointer
Next Thread in C Forum Timeline: Basic Concept





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC