Write a program to display Fibonacci series using C program.





Fibonacci series


 #include <stdio.h>


int main()

{
    int n, first = 0, second = 1, next, i; 
    printf("Enter the number of terms: "); 
    scanf("%d", &n); 
    printf("Fibonacci Series:\n");
    for (i = 0; i < n; ++i) 
    
          // Prints the first two terms as they are predefined 
          if(i <= 1) next = i; else { next = first + second; first = second; second = next;
     }
      printf("%d\n", next); 
 }
  return 0;
}
x

Post a Comment

0 Comments