Please disable your adblock and script blockers to view this page
 

C Language program to generate Fibonacci series up to given limit using For loop

Introduction: In this article i am going to explain the program to generate Fibonacci series/sequence up to the given limit using For loop in C Language.In previous articles i explained the programs to Calculate factorial of a number using for loop and Print table of entered number using For loop and Calculate sum,average and division of marks using else-if ladder and Get number of days in month and year using else if ladder and Find greatest of three numbers using nested if else statement and Goto statement in C language,its advantages and disadvantages with program example.

Description: In Fibonacci series or we can say Fibonacci sequence very first number is 0 and second number is 1 and further next number is sum/addition of previous two numbers.

Fibonacci series with first few numbers can be written as: 0 1 1 2 3 5 8 13 21 34 55.......

For example:
First Number = 0
Second Number = 1
Third Number = 0 + 1 =1
Fourth Number = 1 + 1 =2
Fifth Number = 2 + 1 =3
Sixth Number =3 + 2 = 5
Seventh Number = 5 + 3 =8 and so on...

Implementation: Let's create a program in C language to generate Fibonacci Series with For loop.

#include<conio.h>
#include<stdio.h>
int main()
{
   int i,n,first=0,second=1,fibo;
   clrscr();
   printf("Enter the number of terms: ");
   scanf("%d",&n);
   printf("\nFibonacci series:\n");
   printf("%d\t%d",first,second);
   for(i=0;i<n-2;i++)
    {
      fibo=first+second;
      first=second;
      second=fibo;
      printf("\t%d",fibo);
    }
  getch();
  return 0;
} 
  • Run the program using Ctrl+F9
Output:
Enter the number of terms: 10
Fibonacci Series

0             1             1             2             3             5             8             13           21           34

Now over to you:
"If you like my work; you can appreciate by leaving your comments, hitting Facebook like button, following on Google+, Twitter, Linked in and Pinterest, stumbling my posts on stumble upon and subscribing for receiving free updates directly to your inbox . Stay tuned and stay connected for more technical updates."
Previous
Next Post »

If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily.. ConversionConversion EmoticonEmoticon