This program will print Fibonacci series.it will print number of terms as per user wants.the sample Fibonacci series is as following:
1,1,2,3,5,8,13,21.......
Logic: 1,1,1+1,1+2,2+3,3+5......it means that the next term of the series is the addition of the last two terms.
Program:
#include<stdio.h>
#include<conio.h>
main()
{
unsigned long int a,b,c,ans,i;
clrscr();
printf("=====Fabonicci series=====");
printf("\n\n!!!!!You can calculate correctly till 47 terms!!!!!");
printf("\n\nEnter number: ");
scanf("%ld",&ans);
i=1;
a=0;
b=1;
while(i<=ans)
{
printf(", %ld",a);
c=a+b;
a=b;
b=c;
i=i+1;
}
getch();
}
1,1,2,3,5,8,13,21.......
Logic: 1,1,1+1,1+2,2+3,3+5......it means that the next term of the series is the addition of the last two terms.
Program:
#include<stdio.h>
#include<conio.h>
main()
{
unsigned long int a,b,c,ans,i;
clrscr();
printf("=====Fabonicci series=====");
printf("\n\n!!!!!You can calculate correctly till 47 terms!!!!!");
printf("\n\nEnter number: ");
scanf("%ld",&ans);
i=1;
a=0;
b=1;
while(i<=ans)
{
printf(", %ld",a);
c=a+b;
a=b;
b=c;
i=i+1;
}
getch();
}