I need help with array

I wanted to print fibonacci numbers in given rage and i don't know how to do it.

I wrote this:

int main ()
{
unsigned n;
unsigned m;

printf("Please write the range of fibonacci numbers: ");
scanf("%u%u",&m,&n);
unsigned i;

int f[n-1];
for (i = m; i <= n; i++)
{

f[i] = f[i-1] + f[i-2];



printf ("f[%u]=%u\n", i, f[i]);
}
return 0;
}
You don't need an array. You just need to keep the two previous values in memory.
However, you need to start the serie from start, not from m (unless you have another way to calculate m'th term directly).

Thus,
* calculate the series up to n'th term
* print -- if in range
Topic archived. No new replies allowed.