Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- float f(float x);
- int main(void) {
- int a, b, i, n;
- printf("a: "); scanf("%d", &a);
- printf("b: "); scanf("%d", &b);
- printf("n: "); scanf("%d", &n);
- float h = (float) (b - a) / n, sigma = 0, x = a;
- for (i = 0; i < n; i++)
- {
- sigma += f((x + (x = x + h)) / 2) * h;
- }
- printf("%f\n", sigma);
- return 0;
- }
- float f(float x) {
- return 1 / x;
- }
Add Comment
Please, Sign In to add comment