Computing the Fibonacci Sequence | C Programming Example

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Thanks for the explanation, Recursion is hard for new programmers :
// Iterative solution
void Fibonacci_Iterative (int Sequence_Length){
int first = 0, second = 1, third;
printf("%d, %d, ", first, second);
for(int i = 2 ; i < Sequence_Length ; i++){
third = first + second;
printf("%d", third);
first = second;
second = third;
if(i != Sequence_Length-1)
printf(", ");
else
printf("\n");
}
}
// Recursive solution
int Fibonacci_Recursion(int Position){
if(Position > 1)
return Fibonacci_Recursion(Position - 1) + Fibonacci_Recursion(Position - 2);
if(Position == 0)
return 0;
if(Position == 1)
return 1;
printf("Invalid position !!\n");
return -1;
}

justcurious
Автор

you're such a great teacher !. Your videos are really helpful, tysm!!

chalz
Автор

sir are these programs helpful for campus recruitments

chinni
Автор

Great video! thank you for the clear and logical explanation :)

maniyaa_
Автор

Ooooh that's really understandable...
Thank 💕

miarayokik.s.h
Автор

Not working for 48 the values are going in negative

rakshaya
Автор

anyone that did not get how that recursion function works. use a pen and paper ✅

abdoTheDS
Автор

I think that I did it better
void fun (int x){
int y= x, i ;
printf("%d\n", x);
printf("%d\n", x+=1);
for(i = 0;i < 10;i++){
y= (x+y);
printf("%d\n", y);
x= (x+y);
printf("%d\n", x);
}
}
main
int main(void) {
int x;
printf("Enter a #: ");
scanf("%d", &x);
fun(x);
return 0;
}
+ Thank u so much❤❤

Abdalrahman_
visit shbcf.ru