Advertisement
luizaspan

(TAREFA 3) Int I

May 14th, 2015
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.44 KB | None | 0 0
  1. // calcular numericamente int_{0.1}^{1.0} (1/x)dx = -ln(0.1)
  2. // calcular pela regra retangular
  3.  
  4. #include <stdio.h>
  5. #include <math.h>
  6.  
  7. #define n 1000
  8.  
  9. int main(void)
  10. {
  11.   int i;
  12.   double h,x,sum=0.0,val,e;
  13.  
  14.   h=(1.0-0.1)/n;
  15.  
  16.   for (i=1;i<=n;i++)
  17.     {
  18.       x=0.1+h*i;
  19.       sum+=h*(1/x);
  20.     }
  21.  
  22.   val=-log(0.1);
  23.   e=((val-sum)/val)*100;
  24.  
  25.   printf("Valor calculado: %lf\n",sum);
  26.   printf("Valor real: %lf\n",val);
  27.   printf(
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement