DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C (http://www.daniweb.com/forums/forum118.html)
-   -   Fibonacci number (http://www.daniweb.com/forums/thread33784.html)

morgan_morgen Oct 12th, 2005 5:57 pm
Fibonacci number
 
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.
#include <stdio.h>      
unsigned int f(int n) {
 int i;
  unsigned int last=0,current=1;
int result;

for(i=1; i<=n; i++) {
        last+=current;
//????????
 
  printf("-%d",last);
       
    }
    return last;
}
void f_print(int n) {
    printf("%d\n",n,f(n));
}
int main(void) {
    f_print(10);
    return 0;
}

Gary King Oct 12th, 2005 6:47 pm
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.


All times are GMT -4. The time now is 1:31 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC