C program to print Fibonacci Series

If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().

#include<stdio.h>
main()
{
 int a=1,b=1,c,n,i;

//Accepting limit of series
 printf("Enter the limit \n");
 scanf("%d",&n);

//Febonacci series logic
 printf("%d\t",a);
 printf("%d\t",b);
 for(i=0;i<n;i++)
 {
  c=a+b;
  printf("%d\t",c);
  a=b;
  b=c;
 }
}

OUTPUT:

Enter the limit
5

1       1       2       3       5       8       13

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.