ybh6336
01-14-2003, 02:05 PM
Hello guys
I'm having trouble with the basics of C programming. I have the following code (which I had to write to check the problem in a larger program):
#include<stdio.h>
int fibonacci(int);
int main()
{
int result, i;
for(i=0; i<=4; i++)
{
result = fibonacci(i);
printf("%d ", result);
}
return 0;
}
int fibonacci(int num)
{
int result;
if(num < 2)
{
result = 1;
}
else
{
result = fibonacci(num-1) + fibonacci(num-2);
}
return(result);
}
I want to make function 'fibonacci()' return an integer pointer instead of an integer, something like an array which has the whole fibonacci sequence. What changes do i need to make?
Thanks
-ybh6336
I'm having trouble with the basics of C programming. I have the following code (which I had to write to check the problem in a larger program):
#include<stdio.h>
int fibonacci(int);
int main()
{
int result, i;
for(i=0; i<=4; i++)
{
result = fibonacci(i);
printf("%d ", result);
}
return 0;
}
int fibonacci(int num)
{
int result;
if(num < 2)
{
result = 1;
}
else
{
result = fibonacci(num-1) + fibonacci(num-2);
}
return(result);
}
I want to make function 'fibonacci()' return an integer pointer instead of an integer, something like an array which has the whole fibonacci sequence. What changes do i need to make?
Thanks
-ybh6336