C Program to print the terms of Fibonacci Series upto a certain number

programming coding blue hands digital keyboard fingers

Fibonacci series each member is the sum of the last two terms except the first and second term.
The following C program prints the members of the Fibonacci series upto a certain number, given by the user.

PROGRAM:

/***************************
 *******FIBONACCI***********
 2017 (c) Manas Sharma - https://bragitoff.com 
 **************************/
#include<stdio.h>
void fibonacci(int n){
  int x[2];
  int y;
  x[0]=0;
  x[1]=1;
  printf("\n0\n1");
  y=x[0]+x[1];
  while(y<=n){
    printf("\n%d",y);
    x[0]=x[1];
    x[1]=y;
    y=x[0]+x[1];
  }
}
main(){
  int n;
  printf("Enter a number till which you want to generate Fibonacci numbers:\n");
  scanf("%d",&n);
  printf("\nThe Fibonacci numbers till %d are: \n",n);
  fibonacci(n);
}

OUTPUT:

[wpedon id="7041" align="center"]

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.