TO FIND FIBONACCI SERIES USING C PROGRAM





Code 1:
1. Write a program to generate the Fibonacci series in c
2. Write a program to print Fibonacci series in c
3. Basic c programs Fibonacci series
4. How to print Fibonacci series in c
5. How to find Fibonacci series in c programming
6. Fibonacci series in c using for loop

#include<stdio.h>
int main(){
    int k,r;
    long int i=0l,j=1,f;

    //Taking maximum numbers form user
    printf("Enter the number range:");
    scanf("%d",&r);

    printf("FIBONACCI SERIES: ");
    printf("%ld %ld",i,j); //printing firts two values.

    for(k=2;k<r;k++){
         f=i+j;
         i=j;
         j=f;
         printf(" %ld",j);
    }
  
    return 0;
}

Sample output:
Enter the number range: 15
FIBONACCI SERIES: 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

Code 2:
1. Fibonacci series using array in c
2. Fibonacci series program in c language
3. Source code of Fibonacci series in c
4. Wap to print Fibonacci series in c

#include<stdio.h>
int main(){

    int i,range;
    long int arr[40];

    printf("Enter the number range: ");
    scanf("%d",&range);

    arr[0]=0;
    arr[1]=1;

    for(i=2;i<range;i++){
         arr[i] = arr[i-1] + arr[i-2];
    }

    printf("Fibonacci series is: ");
    for(i=0;i<range;i++)
         printf("%ld ",arr[i]);
  
    return 0;
}

Sample output:
Enter the number range: 20
Fibonacci series is: 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181

Code 3:
1. Fibonacci series in c using while loop
2. C program to calculate Fibonacci series
3. C program to display Fibonacci series
4. Fibonacci series in c with explanation
5. C code to generate Fibonacci series

#include<stdio.h>
int main(){
    int k=2,r;
    long int i=0l,j=1,f;

    printf("Enter the number range:");
    scanf("%d",&r);

    printf("Fibonacci series is: %ld %ld",i,j);

    while(k<r){
         f=i+j;
         i=j;
         j=f;
         printf(" %ld",j);
          k++;
    }
  
    return 0;
}


Sample output:
Enter the number range: 10
Fibonacci series is: 0 1 1 2 3 5 8 13 21 34

Code 4:
1. Sum of Fibonacci series in c

#include<stdio.h>
int main(){
    int k,r;
    long int i=0,j=1,f;
    long int sum = 1;

    printf("Enter the number range: ");
    scanf("%d",&r);

    for(k=2;k<r;k++){
         f=i+j;
         i=j;
         j=f;
         sum = sum + j;
    }

    printf("Sum of Fibonacci series is: %ld",sum);
  
    return 0;
}

Sample output:
Enter the number range: 4
Sum of Fibonacci series is: 4


Algorithm:

What is Fibonacci series?

Logic of Fibonacci series

Definition of Fibonacci numbers:


We assume first two Fibonacci are 0 and 1
A series of numbers in which each sequent number is sum of its two previous numbers is known as Fibonacci series and each numbers are called Fibonacci numbers. So Fibonacci numbers is

Algorithm for Fibonacci series 

Fn = Fn-2 + Fn-1

Example of Fibonacci series:

0 , 1 ,1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55  ...

5 is Fibonacci number since sum of its two previous number i.e. 2 and 3 is 5
8 is Fibonacci number since sum of its two previous number i.e. 3 and 5 is 8 and so on.






10. Write a c program to add two numbers without using addition operator.
11. Write a c program to subtract two numbers without using subtraction operator.
15. Write a c program to solve quadratic equation.
18. Write a c program which passes structure to function.
28. Write a c program which takes password from user.
29. Write a scanf function in c which accept sentence from user.
30. Write a scanf function in c which accept paragraph from user.

26 comments:

  1. Plese Correct the line where "While" starts.........By

    while(k<=r)

    Using For loop The programa is.....
    void main()
    {
    int i=0,j=1,k,r,f;
    clrscr();
    printf("Enter the number range:");
    scanf("%d",&r);
    printf("\nFIBONACCI SERIES: ");
    printf("%d %d",i,j);
    for (k = 2; k <= r; k++)
    {
    f = i + j;
    i = j;
    j = f;
    printf(" %d",j);
    }
    getch();
    }

    "Thanks everybody for the program"

    ReplyDelete
  2. Your blog keeps getting better and better! Your older articles are not as good as newer ones you have a lot more creativity and originality now keep it up!

    ReplyDelete
  3. Thanks you very much

    ReplyDelete
  4. void main()
    {
    int i,a=0,b=1,c=0,n;
    clrscr();
    printf("\n Enter the lenth of the sequence: ");
    scanf("%d",&n);
    if(n==0)
    {
    printf("\nPlease enter more than 0 and try again.");

    }

    else
    {
    if(n==1)
    {
    printf("\n The fibonacci serice of given length is: ");
    printf("\n\n %d",a);
    // getch();
    }
    else if(n==2)
    {
    printf("\n The fibonacci serice of given length is: ");
    printf("\n\n %d\t%d",a,b);
    }
    else
    {
    printf("\n The fibonacci serice of given length is: ");
    printf("\n\n %d\t%d",a,b);
    for(i=3;i<=n;i++)
    {
    c=a+b;
    a=b;
    b=c;
    printf("\t%d",c);
    }
    }
    }
    getch();
    }

    ReplyDelete
  5. #include
    #include
    #include
    void main()
    {
    int n,i,c;
    int a=0;
    int b=1;
    clrscr();
    printf("Enter the number of terms=");
    scanf("%d",&n);
    printf("Fibonacci Series");
    printf("\n%d\n%d"a,b);
    for (i=3;i<=n;i++)
    {
    c=a=b;
    a=b;
    b=c;
    printf("\n%d",c);
    }
    getch();
    }

    ReplyDelete
  6. saumya pandey12/19/11, 12:27 PM

    thanks a lot this is great

    ReplyDelete
  7. write a c program to implement the single shorted path problem.






    thank you.

    ReplyDelete
  8. Thank u very much for Fibonacci series post.

    ReplyDelete
  9. Thank u very much for Fibonacci series post.but i also need wap Fibonacci series using iterative function

    ReplyDelete
  10. #include
    #include
    void main()
    {
    int i=0,j=1,k,n,count=1;
    printf("No. of elements");
    scanf("%d",&n);
    while(count<=n)
    {
    printf("%d\t",i);
    k=i;
    i=i+j;
    j=k;
    count++;
    }
    getch();
    }
    REPLY

    ReplyDelete
  11. what will b the output

    char * p="Hello";

    ?=(*p)*;

    ReplyDelete
  12. A simple way to print fibonacci numbers.

    #include
    main()
    {
    int a = 0, b = 1, c;
    printf("Enter range");
    scanf("%d\n",&range);
    if(range)
    printf("%d ",a);
    while(--range)
    {
    c = a + b;
    a = b;
    b = c;
    printf("%d ",a);
    }
    }

    ReplyDelete
    Replies
    1. idea ok. but not working properly for range=0;
      i corrected it.

      #include
      #include

      main()
      {
      int a = 0, b = 1, c=0, range=0;
      clrscr();
      printf("Enter range");
      scanf("%d",&range);
      printf("range %d", range);
      getch();
      if(range)
      while(--range)
      {
      c = a + b;
      a = b;
      b = c;
      printf("\n%d ",a);
      }
      else
      printf("%d",a);
      getch();
      return (0);
      }

      Delete
  13. #include
    #include
    void main()
    {
    clrscr();
    int a=0,b=1,c=0,n;
    cout<<"Enter the number of terms you wanna see: ";
    cin>>n;
    cout<<a<<" "<<b<<" ";
    for(int i=1;i<=n-2;i++)
    {
    c=a+b;
    a=b;
    b=c;
    cout<<c<<" ";
    }
    getch();
    }

    ReplyDelete
  14. can you please solve this??

    Write a program to calculate the sum of former 40 numbers of series 2/1, 3/2, 5/3, 8/5, 13/8, 21/13,……

    ReplyDelete
  15. How to write a program that will display the sum of the given range.
    Sample output: Enter number of range to be added: 5
    The sum of given range is: 15

    ReplyDelete
  16. Everything is very open with a clear description of the issues. Many thanks for sharing!

    Greetings from Torrent

    ReplyDelete
  17. Questions : - Sir please help out on this.?
    1.Print the following pattern:
    A B C D E D C B A
    A B C D C B A
    A B C B A
    A B A
    A

    2. Generate Fibonacci series from 1 to 100 and print it in reverse order.

    3. Write an efficient program to reverse characters of each word in a file and write an output file in the same format with all words reversed.

    4. Explain the order of complexity in Big-Oh notation, and time taken to process?

    5. Work out an algorithm to predict the best times to buy and sell a stock over a 60-day period. Use a suitable data structure so that the “n” th element is the price of the stock on day “n”.
    ex. 1st element is stock price on day one, 60th element is stock price on day 60.Assume that you start out with 10,000 INR, and value of stock on day 1 is INR 10. Make up any data that you wish for the stock prices. Please provide the input dataset and a working program.

    ReplyDelete
    Replies
    1. Ans 2:
      #include

      void main()
      {
      int num=100,i=0,j=1,k=0,n=0;
      i=-1;
      k=i+j;
      //FINDING LAST ELEMENT
      while(1)
      {
      k=i+j;
      if(k>num)
      break;
      i=j;
      j=k;
      }
      //PRINTING OUTPUT
      while(j>=1)
      {
      k=j-i;
      printf("%d ",j);
      j=i;
      i=k;
      }
      //ADDING LAST 0
      printf("0\n");
      }

      Delete
  18. here is a simplest way
    /* Fibonacci Series c language */
    #include
    #include
    void main()
    {
    int f=0,s=1,ne=0,n,i;
    clrscr();
    printf("Enter any integer value\n");
    scanf("%d",&n);
    printf("%d",f);
    for (i=0;i<n;i++)
    {
    ne=f+s;
    printf("+%d",ne);
    s=f;
    f=ne;
    }
    getch();
    }

    ReplyDelete
  19. Fibonacci series
    =============
    #include

    void main()
    {
    int num,i=0,j=1,k,n;
    printf("Enter the number of elements: \n");
    scanf("%d",&num);
    i=-1;
    for(n=0;n<num;n++)
    {
    k=i+j;
    printf("%d ",k);
    i=j;
    j=k;
    }
    }

    ReplyDelete
  20. write a program to find a. surface area (A=apr2)
    b. volume (v=4/3 p3)

    ReplyDelete
  21. Great post... but the fab numbers start at 1 not 0. SHould be a quick fix :)

    ReplyDelete