- 1
Please help to find mistake
#include <stdio.h> int fibonacci (int i) int main() { int i; for (i=1;i<=10;i++) { printf ("%d\t\n",fibonacci(i)); } } int fibonacci (int i) { if(i==0) } if(i==1) { return 1; } return fibonacci (i_1)+fibonacci (i_2); } https://www.sololearn.com/discuss/2948633/?ref=app https://www.sololearn.com/discuss/2947723/?ref=app https://www.sololearn.com/discuss/2947797/?ref=app https://www.sololearn.com/discuss/2947957/?ref=app https://www.sololearn.com/discuss/2948551/?ref=app https://www.sololearn.com/discuss/2948816/?ref=app https://www.sololearn.com/discuss/2948323/?ref=app
2 odpowiedzi
+ 6
Ganesh Neupane ,
please do not attach unrelated links in your post. this can be considered as spam, that may be deleted.
+ 3
Man, Fibonacci implementation in C is a basic one, along with factorial. But you did some big mistakes.
#include <stdio.h>
int fibonacci(int fib); //semicolon is required on a prototype function
int main() {
int i = 0; //always initialize your variables
//you can read a variable from stdin (keyboard) to calculate Fibonacci until that number
int n = 0, m = 0;
scanf("%d", &n);
printf("Fibonacci series until the number: %d\n\n", n);
//replace 10 with n
for (i=1;i<=n;i++) {
printf ("%d\n",fibonacci(m));
m++;
}
return 0;
}
int fibonacci(int fib) {
if(fib==0 || fib==1) {
return fib;
}
else {
return fibonacci(fib-1) + fibonacci(fib-2);
}
}
LE: I commented and explained the above solution. It is recommended for beginners in C programming language.
https://code.sololearn.com/cYq4NAqBAiUe/?ref=app