zeno.c 458 B

1234567891011121314151617181920
  1. /* zeno.c -- series sum */
  2. #include <stdio.h>
  3. int main(void)
  4. {
  5. int t_ct; // term count
  6. double time, power_of_2;
  7. int limit;
  8. printf("Enter the number of terms you want: ");
  9. scanf("%d", &limit);
  10. for (time=0, power_of_2=1, t_ct=1; t_ct <= limit;
  11. t_ct++, power_of_2 *= 2.0)
  12. {
  13. time += 1.0/power_of_2;
  14. printf("time = %f when terms = %d.\n", time, t_ct);
  15. }
  16. return 0;
  17. }