Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- #include<math.h>
- int n1, n2;
- float p[10], q[10];
- float f(float x)
- {
- float d = p[0];
- for (int i = 1; i<=n1; i++) d = d*x + p[i];
- return d;
- }
- float g(float x)
- {
- float d = q[0];
- for (int i = 1; i<=n2; i++) d = d*x + q[i];
- return d;
- }
- float tichphan(float (*f) (float), float a, float b)
- {
- int n = 1000;
- float h = (b-a)/n;
- float s = (f(a)+f(b))/2;
- for (int i = 1; i<n; i++) s+= f(a+i*h);
- return s*h;
- }
- int main()
- {
- char tt;
- int i, j;
- float a,b;
- printf("\nNhap ham f(x): ");
- printf("\nNhap bac cua ham f(x): ");
- scanf("%d",&n1);
- for ( i = 0; i<=n1; i++)
- {
- printf("A[%d] = ",i);
- scanf("%f",&p[i]);
- }
- printf("\nNhap ham g(x): ");
- printf("\nNhap bac cua ham g(x): ");
- scanf("%d",&n2);
- for ( i = 0; i<=n2; i++)
- {
- printf("A[%d] =",i);
- scanf("%f",&q[i]);
- }
- printf("\n%d %d",n1,n2);
- while (1)
- {
- printf("\nNhap can a, b :");
- scanf("%f%f",&a,&b);
- printf("\nTich phan ham f(x) = %f",tichphan(f,a,b));
- printf("\nTich phan ham g(x) = %f",tichphan(g,a,b));
- printf("\nBan co muon tiep tuc (c/k)?");
- tt = getch();
- if (tt!='c') break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement