Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- /* This assumes that
- * a(1) = 1
- * a(2) = -4 / 6
- * a(3) = 7 / 11
- * and so on.
- * Modify computeTerm() if the second term is wrong.
- */
- double computeTerm(int n)
- {
- double sign = (n % 2) ? -1.0 : 1.0;
- double numerator = 2.0 - 3.0 * n;
- double denominator = 5.0 * n - 4.0;
- return sign * numerator / denominator;
- }
- double computeSeries(int n)
- {
- double sum = 0;
- int i;
- for(i = 1; i <= n; i++) {
- sum += computeTerm(n);
- }
- return sum;
- }
- int main()
- {
- int i;
- for(i = 1; i <= 100; i++) {
- printf("%d %.4f\n", i, computeSeries(i));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement