Fibonnaci Number in C language
The Fibonacci Sequence is the series of numbers:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
The next number is found by adding up the two numbers before it.
if you want to search the x-th fibonacci digit you can use this code
int main()
{
int fib,a,b,c,f;
scanf("%d",&fib);
a=0;
b=1;
c=0;
for(f=1;f<fib;f++)
{
c=a+b;
a=b;
b=c;
}
printf("the fibonacci %dth digit is %d",fib,c);
return 0;
}
or you want print the all the list of fibonacci number
#include<stdio.h>
int main()
{
int fib,a,b,c,f;
scanf("%d",&fib);
a=0;
b=1;
c=0;
printf("%d digit of fibonnaci\n",fib);
printf("%d %d",a,b);
for(f=1;f<fib;f++)
{
c=a+b;
a=b;
b=c;
printf(" %d",c);
}
return 0;
}
that is all from me
thank you
Comments
Post a Comment