Advertisement
kiwser

Fibonacci Series

Aug 22nd, 2021
957
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.33 KB | None | 0 0
  1. #include <stdio.h>
  2. int main()
  3. {
  4.   int i, n, l1 = 0, l2 = 1;
  5.   int nextTerm = l1 + l2;
  6.   printf("Enter the number: ");
  7.   scanf("%d", &n);
  8.   printf("Fibonacci Series: %d, %d, ", l1, l2);
  9.   for (i = 3; i <= n; ++i)
  10.   {
  11.     printf("%d, ", nextTerm);
  12.     l1 = l2;
  13.     l2 = nextTerm;
  14.     nextTerm = l1 + l2;
  15.   }
  16.  
  17.   return 0;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement