Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.40 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. double sum_arithmetic(double x0, double r, int n)
  5. {
  6.  return n == 0 ? 0 : x0 + sum_arithmetic(x0 + r, r, n-1);
  7. }
  8.  
  9. void test_sum_arithmetic(void)
  10. {
  11.     double x0;
  12.     double r;
  13.     int n;
  14.     while (scanf("%f%f%d", &x0, &r, &n) !=EOF)
  15.     {
  16.         double z = sum_arithmetic(x0, r, n);
  17.         printf("%f\n", z);
  18.     }
  19. }
  20.  
  21. int main(void)
  22. {
  23.     test_sum_arithmetic();
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement