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:

I'm a physicist specializing in theoretical, computational and experimental condensed matter physics. I like to develop Physics related apps and softwares from time to time. Can code in most of the popular languages. Like to share my knowledge in Physics and applications using this Blog and a YouTube channel.



Leave a Reply

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