The fibonacci series is like 0,1,1,2,3,5,8,13,24,55,89......We can get this like first two are 0 and 1 from third number on wards we have to add the previous two numbers for example to get the 5th number in the series we need to add 3rd and 4th numbers in the series.
#include<stdio.h>
int main()
{
int i,a=0,b=1,s=0,r;
printf("\n Enter range:");
scanf("%d",&r);
printf("%d \n",a);
printf("%d \n",b);
while(s<=r)
{
s=a+b;
if(s<=r)
{
printf("%d \n",s);
}
a=b;
b=s;
}
getch();
}
#include<stdio.h>
int main()
{
int i,a=0,b=1,s=0,r;
printf("\n Enter range:");
scanf("%d",&r);
printf("%d \n",a);
printf("%d \n",b);
while(s<=r)
{
s=a+b;
if(s<=r)
{
printf("%d \n",s);
}
a=b;
b=s;
}
getch();
}
No comments:
Post a Comment