Skip to main content

C Program to Generate and Print Fibonacci series upto a given inputted number

 C Program to Generate and Print Fibonacci series upto a given inputted number

    In this example, we will generate and print fibonacci series upto a the upper limit entered by the user. To solve this problem we should have a proper concept on Fibonacci series and while loop. 


What is a Fibonacci Series?

Fibonacci series is the sum of the two preceding numbers, starting from 0 and 1.

    For Example: 0,1,1,2,3,5,8,13,....,etc 



PROGRAM

#include<stdio.h>
#include<conio.h>
void main()
{
    int n,x1,x2,x3=0;
    printf("Enter the limit upto which fibonacci series to be generated : ");
    scanf("%d",&n);
    x1=0;
    x2=1;
    printf("%d\t%d",x1,x2);
    x3=x1+x2;
    while(x3<=n)
    {
        printf("\t%d",x3);
        x1=x2;
        x2=x3;
        x3=x1+x2;
    }
    getch();
}


OUTPUT:

Enter the limit upto which fibonacci series to be generated : 30

0       1       1       2       3       5       8       13      21



NOTE: You Can Comment Your Code if you have solved differently and we will pin it in the comment section.  Let's Learn together. 


MOTTO: 

You Learn, I Learn together We Learn.

Comments

Popular posts from this blog

C Program to Print first N Even Natural Number/in Reverse Order

  C Program to Print first N Even Natural Number.     In this example, we will find and print the first N even natural. Here we have used for loop to solve this program.      What are Natural Numbers? Natural Numbers are all positive numbers starting from 1 to infinity.      For Example:  1,2,3,4,5,6,.............................,n are all natural numbers. What are Even Numbers? Even numbers are those numbers whose remainder is 0 when divided by 2.     For Example: 2,4,6,8,10,.....,n are all even numbers.   PROGRAM: #include <stdio.h> #include <conio.h> void   main () {      int   i , x ;      printf ( "Enter the value of N : " );      scanf ( " %d " ,& x );      for ( i = 1 ; i <= x ; i ++)     {          printf ( " %d " , 2 * i );     }      getch (); } OUTPUT: C Program to Print First N Even Natural Number in Reverse Order. PROGRAM 123 #include <conio.h> #include <stdio.h> int   main () {      int   i , x ;      printf