Fibonacci Sequence :
The Fibonacci sequence is a series where each number is the sum of the two preceding ones, starting from 0 and 1.
Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89
File Name : fibonacci.c
#include <stdio.h>
void main()
{
int t1=0,t2=1,t3,n,i;
printf("Enter number of terms to generate sequence: ");
scanf("%d",&n);
printf("Generated Fibonacci Series Of %d terms is:\n",n);
for(i=1;i<=n;++i)
{
printf("%d\n",t1);
t3=t1+t2;
t1=t2;
t2=t3;
}
}
Output1:
Enter number of terms to generate sequence: 3
Generated Fibonacci Series Of 3 terms is:
0
1
1
Output1:
Enter number of terms to generate sequence: 6
Generated Fibonacci Series Of 6 terms is:
0
1
1
2
3
5
The Fibonacci sequence is a series where each number is the sum of the two preceding ones, starting from 0 and 1.
Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89
File Name : fibonacci.c
#include <stdio.h>
void main()
{
int t1=0,t2=1,t3,n,i;
printf("Enter number of terms to generate sequence: ");
scanf("%d",&n);
printf("Generated Fibonacci Series Of %d terms is:\n",n);
for(i=1;i<=n;++i)
{
printf("%d\n",t1);
t3=t1+t2;
t1=t2;
t2=t3;
}
}
Output1:
Enter number of terms to generate sequence: 3
Generated Fibonacci Series Of 3 terms is:
0
1
1
Output1:
Enter number of terms to generate sequence: 6
Generated Fibonacci Series Of 6 terms is:
0
1
1
2
3
5
No comments:
Post a Comment