Hey guys,
This is a hmwk problem of mine that I've been caught up in for a while now.... I need some suggestions to help me figure out what I'm missing, I'm sure it's a minor detail...
Just so I get everyone on the same page :
-This program needs to request from the user the 'x' number or Fibonacci numbers that need to be printed.
-Uses a recursive function to compute the fist 'x' fibonacci numbers
- Prints the first 'x' fibonacci numbers.
Here is what I have up to this point. (I HAVE looked at other examples on this site, but they differ from what I am trying to do... I do not like to blend other codes into mine, as it leads to confusion on my end, and I do want to know what the hell is going on. Any help would be great, thx guys.)
You will notice I have commented a while loop and index with question marks.... I really don't know if I need these or not, all I know it that i can't get my fibonacci functions to print out... (I am limiting the user to enter only the 1st 20 numbers)
I am pretty sure my function is correct, but my main function is screwy...
Code:
#include<stdio.h>
double fib(int num)
{
if(num<0) {
return 0;
}
else if(num==0) {
return 1;
}
else if(num<=20) {
return (fib(num-1)+fib(num-2));
}
else {
printf("The integer you gave is too large\n");
return 0;
}
}
int main()
{
double num;
/* ?? int index=0; ?? */
printf("Give an integer from 0 to 20:");
scanf("%d", &num);
/* ??? while(num>=0)
index++; ??? */
printf("The first %d fibonacci numbers are:\n", num);
printf("fibonacci(%d) = %1.01f\n", num, fib(num));
}