LEONARDO OF PISA
Problem Description
The Fibonacci sequence is named after Italian mathematician Leonardo of Pisa, known as Fibonacci. His 1202 book Liber Abaci introduced the sequence to Western European mathematics although the sequence had been described earlier in Indian mathematics. The sequence described in Liber Abaci began with F1 = 1. Implement Liber Abaci Number
CODING ARENA
#include <stdio.h>
int main()
{
int i,n,t1=0,t2=1,nextTerm;
scanf("%d",&n);
for(i=1;i<=n;++i)
{
printf("%d\n",t1);
nextTerm=t1+t2;
t1=t2;
t2=nextTerm;
}
return 0;
}
Test Case 1
Input (stdin)10
Expected Output
0
1
1
2
3
5
8
13
21
34
Test Case 2
Input (stdin)3
Expected Output
0
1
1
No comments:
Post a Comment