fork download
  1. void printFibonacciNumbers()
  2. {
  3. int f1 = 0, f2 = 1, i,n;
  4. scanf("%d",&n);
  5. if (n < 1)
  6. return;
  7.  
  8. for (i = 1; i <= n; i++)
  9. {
  10. printf("%d ", f2);
  11. int next = f1 + f2;
  12. f1 = f2;
  13. f2 = next;
  14. }
  15. }
  16.  
  17. // Driver Code
  18. int main()
  19. {
  20. printFibonacciNumbers();
  21. return 0;
  22. }
Success #stdin #stdout 0s 9424KB
stdin
5
stdout
1 1 2 3 5