Advertisement
Guest User

Untitled

a guest
Sep 19th, 2014
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. float Rectangle(float a, float b, int n)
  2. {
  3. float res = 0;
  4. for(int k=0;k<n;k++)
  5. {
  6. res = res + 1/(a + k*((b-a)/n));
  7. }
  8. res = res * ((b-a)/n);
  9. return res;
  10. }
  11.  
  12. float Milieu(float a, float b, int n)
  13. {
  14. float res =0;
  15. for(int k=0;k<n;k++)
  16. {
  17. res = res + 1/(a + (2*k +1) * ((b-a)/(2*n)));
  18. }
  19. res = res * ((b-a)/n);
  20. return res;
  21. }
  22.  
  23. float erreurRectangle(float a, float b, int n)
  24. {
  25.  
  26. }
  27.  
  28. int main()
  29. {
  30. float a = 1.0;
  31. float b = 2.0;
  32. int n = 1;
  33. while(Milieu(a,b,n) < log(2))
  34. {
  35. n++;
  36. }
  37. float res = Milieu(a,b,n);
  38. printf("Res = %f \n", res);
  39. printf("n = %d",n);
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement