SHARE
TWEET

Untitled

a guest Jan 21st, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top