Fibonacci Series up to n number of terms
#include <stdio.h>
int main()
{
int i, j, rows;
printf(“Enter number of rows: “);
scanf(“%d”,&rows);
for(i=1; i<=rows; ++i)
{
for(j=1; j<=i; ++j)
{
printf(“* “);
}
printf(“\n”);
}
return 0;
}
Fibonacci Sequence Up to a Certain Number
#include <stdio.h>
int main()
{
int t1 = 0, t2 = 1, nextTerm = 0, n;
printf(“Enter a positive number: “);
scanf(“%d”, &n);
// displays the first two terms which is always 0 and 1
printf(“Fibonacci Series: %d, %d, “, t1, t2);
nextTerm = t1 + t2;
while(nextTerm <= n)
{
printf(“%d, “,nextTerm);
t1 = t2;
t2 = nextTerm;
nextTerm = t1 + t2;
}
return 0;
}
Fibonacci Series
/*fibonacci series*/
#include<stdio.h>
#include<conio.h>
main()
{
int n,a=1,b=1,c,i;
printf(“Enter the number:”);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
printf(“%d\t”,a);
c=a+b;
a=b;
b=c;
}
getch();
}