fork download
  1. #include <stdio.h>
  2. int main() {
  3. int i, n, t1 = 0, t2 = 1, nextTerm;
  4. printf("Enter the number of terms: ");
  5. scanf("%d", &n);
  6. printf("Fibonacci Series: ");
  7.  
  8. for (i = 1; i <= n; ++i) {
  9. printf("%d ", t1);
  10. nextTerm = t1 + t2;
  11. t1 = t2;
  12. t2 = nextTerm;
  13. }
  14.  
  15. return 0;
  16. }
Success #stdin #stdout 0s 4392KB
stdin
10
stdout
Enter the number of terms: Fibonacci Series: 0 1 1 2 3 5 8 13 21 34