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;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.