Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scratchyourbrain/06223d0fc7a1acf6b4ca to your computer and use it in GitHub Desktop.
Save scratchyourbrain/06223d0fc7a1acf6b4ca to your computer and use it in GitHub Desktop.
C Program to Display Fibonacci Series
#include <stdio.h>
int main()
{
int count, n, t1=0, t2=1, display=0;
printf("Enter number of terms: ");
scanf("%d",&n);
printf("Fibonacci Series: %d %d ", t1, t2); /* Displaying first two terms */
count=2; /* count=2 because first two terms are already displayed. */
while (count<n)
{
display=t1+t2;
t1=t2;
t2=display;
++count;
printf("%d ",display);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment