Fibonacci series?
First two numbers of the fibonacci series is 0 and 1. From third number on words , the series eill be the sum of previous two numbers.
#include <stdio.h>
int main()
{
int f1=0, f2=1, fib_ser, cnt=2, lmt;
printf("Please enter the limit of the Fibonacci series :");
scanf("%d",&lmt);
printf("\nFibonacci series is: \n%d \n%d \n",f1,f2);
while (cnt < lmt)
{
fib_ser=f1+f2;
cnt++;
printf("%d\n",fib_ser);
f1=f2;
f2=fib_ser;
}
return 0;
}
First two numbers of the fibonacci series is 0 and 1. From third number on words , the series eill be the sum of previous two numbers.
#include <stdio.h>
int main()
{
int f1=0, f2=1, fib_ser, cnt=2, lmt;
printf("Please enter the limit of the Fibonacci series :");
scanf("%d",&lmt);
printf("\nFibonacci series is: \n%d \n%d \n",f1,f2);
while (cnt < lmt)
{
fib_ser=f1+f2;
cnt++;
printf("%d\n",fib_ser);
f1=f2;
f2=fib_ser;
}
return 0;
}

No comments:
Post a Comment