fork download
  1. #include <stdio.h>
  2.  
  3. int fibSum10(int n, int a, int b)
  4. {
  5. int t, sum = 0;
  6. while (--n)
  7. {
  8. t = a;
  9. a = b;
  10. b += t;
  11. // sum += b;
  12. }
  13. sum = b;
  14. n = 10;
  15. while (--n)
  16. {
  17. t = a;
  18. a = b;
  19. b += t;
  20. sum += b;
  21. }
  22. return sum;
  23. }
  24.  
  25. int main()
  26. {
  27. for (int i = 1; i < 10; ++i) printf("n = %d, sum = %d\n", i, fibSum10(i, 0, 1));
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0s 2292KB
stdin
Standard input is empty
stdout
n = 1, sum = 143
n = 2, sum = 231
n = 3, sum = 374
n = 4, sum = 605
n = 5, sum = 979
n = 6, sum = 1584
n = 7, sum = 2563
n = 8, sum = 4147
n = 9, sum = 6710