Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- double sum_arithmetic(double x0, double r, int n)
- {
- return n == 0 ? 0 : x0 + sum_arithmetic(x0 + r, r, n-1);
- }
- void test_sum_arithmetic(void)
- {
- double x0;
- double r;
- int n;
- while (scanf("%f%f%d", &x0, &r, &n) !=EOF)
- {
- double z = sum_arithmetic(x0, r, n);
- printf("%f\n", z);
- }
- }
- int main(void)
- {
- test_sum_arithmetic();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement