Guest User

Untitled

a guest
Jan 21st, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. float f(float x);
  4.  
  5. int main(void) {
  6.  
  7. int a, b, i, n;
  8.  
  9. printf("a: "); scanf("%d", &a);
  10. printf("b: "); scanf("%d", &b);
  11. printf("n: "); scanf("%d", &n);
  12.  
  13. float h = (float) (b - a) / n, sigma = 0, x = a;
  14.  
  15. for (i = 0; i < n; i++)
  16. {
  17. sigma += f((x + (x = x + h)) / 2) * h;
  18. }
  19.  
  20. printf("%f\n", sigma);
  21.  
  22. return 0;
  23.  
  24. }
  25.  
  26. float f(float x) {
  27.  
  28. return 1 / x;
  29.  
  30. }
Add Comment
Please, Sign In to add comment