Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<math.h>
  4.  
  5. int n1, n2;
  6. float p[10], q[10];
  7.  
  8. float f(float x)
  9. {
  10. float d = p[0];
  11. for (int i = 1; i<=n1; i++) d = d*x + p[i];
  12. return d;
  13. }
  14. float g(float x)
  15. {
  16. float d = q[0];
  17. for (int i = 1; i<=n2; i++) d = d*x + q[i];
  18. return d;
  19. }
  20. float tichphan(float (*f) (float), float a, float b)
  21. {
  22. int n = 1000;
  23. float h = (b-a)/n;
  24. float s = (f(a)+f(b))/2;
  25. for (int i = 1; i<n; i++) s+= f(a+i*h);
  26. return s*h;
  27. }
  28. int main()
  29. {
  30. char tt;
  31. int i, j;
  32. float a,b;
  33. printf("\nNhap ham f(x): ");
  34. printf("\nNhap bac cua ham f(x): ");
  35. scanf("%d",&n1);
  36. for ( i = 0; i<=n1; i++)
  37. {
  38. printf("A[%d] = ",i);
  39. scanf("%f",&p[i]);
  40. }
  41. printf("\nNhap ham g(x): ");
  42. printf("\nNhap bac cua ham g(x): ");
  43. scanf("%d",&n2);
  44. for ( i = 0; i<=n2; i++)
  45. {
  46. printf("A[%d] =",i);
  47. scanf("%f",&q[i]);
  48. }
  49. printf("\n%d %d",n1,n2);
  50. while (1)
  51. {
  52. printf("\nNhap can a, b :");
  53. scanf("%f%f",&a,&b);
  54. printf("\nTich phan ham f(x) = %f",tichphan(f,a,b));
  55. printf("\nTich phan ham g(x) = %f",tichphan(g,a,b));
  56. printf("\nBan co muon tiep tuc (c/k)?");
  57. tt = getch();
  58. if (tt!='c') break;
  59. }
  60. return 0;
  61.  
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement