First few numbers: 0,1,1,2,3,5,8,13,21,34
Sequence and Formula:
The sequence starts with f=0 & f1=1
Every subsequent number is by adding the two numbers before it.
f2= 0+1 -> 1 1+1 ->2 1+2 -> 3 ........
f2=f1+f
f=f1
f1=f2
#include<stdio.h>
main()
{
int f=0,f1=1,f2=0,i;
printf("\n%d\t%d",f,f1);
for(i=3;i<=10;++i)
{
f2=f1+f;
printf("\t%d",f2);
f=f1;
f1=f2;
}
}
main()
{
int f=0,f1=1,f2=0,i;
printf("\n%d\t%d",f,f1);
for(i=3;i<=10;++i)
{
f2=f1+f;
printf("\t%d",f2);
f=f1;
f1=f2;
}
}
Output
No comments:
Post a Comment