1. ## Fibonacci

prob-B.pdf

And this is my code that related to the question :
Code:
```#include <stdio.h>

typedef unsigned long long F;

F fibonacci(F n);

int main()
{
int n, i, j;

printf("--- Fibonacci series program ---\n");
printf("Enter a number:");
scanf("%d",&n);

printf("\nFibonacci series:\n");
j = 0;
for ( i = 1 ; i <= n ; i++ )
{
printf("%d ", fibonacci(j));
j++;
}
}

F fibonacci(F n)
{
int i;
F f1 = 0;
F f2 = 1;
F fi;

if(n == 0)
return 0;
if(n == 1)
return 1;

for(i = 2 ; i <= n ; i++ )
{
fi = f1 + f2;
f1 = f2;
f2 = fi;
}
return fi;
}``` 2. fibonacci() returns an unsigned long long, but the printf is using "%d", which is for a signed int. For Visual Studio, the printf would use "%llu" for an unsigned long long. 3. Originally Posted by Audy Naufal prob-B.pdf

And this is my code that related to the question :
Code:
```#include <stdio.h>

int main()
{
int n, i, j;

printf("--- Fibonacci series program ---\n");
printf("Enter a number:");
scanf("%d",&n);

printf("\nFibonacci series:\n");
j = 0;
for ( i = 1 ; i <= n ; i++ )
{
printf("%d ", fibonacci(j));
j++;
}
}```
The program run almost correct; "j" is redundant.

Code:
```int main(void)
{
int n;  //i -> NO!

printf("--- Fibonacci series program ---\n");
printf("Enter a number:");
scanf("%d",&n);

printf("\nFibonacci series:\n");
//Start with '0' else for example: n = 6 -> solution = 5, that is wrong
for (int i = 0 ; i <= n ; i++ )
{
printf("%d ", fibonacci(i));
}
return(0);
}``` Popular pages Recent additions int, long, program, series, urgent 