I am trying to use the Simpson's Method to calculate area under the curve using this function 2x^2+x but its not working?
Can some one help me and fix the problem? Its using Simpson's Method and want user to input a,b and N then calculate the area of the function given 2x^2+x
insertCode:#include <stdio.h> #include <conio.h> #include <cstdlib> double simpson(double a, double b, int n); double fk(double x); //********************************** int main() { double a,f,b; int n; //Duomenys---------------- printf("Enter value of a, example a=0\n a:"); scanf("%lf", &a); //------------------------ printf("Enter value of n, example n=7\n n:"); scanf("%d",&n); printf ("Enter Value of b, example b=1\nb:"); scanf("%lf", &b); f=simpson(a ,b , n); // Integralas //Rezultatas---------------- printf("The result is f=%7.2f\n",f); } //********************************** double simpson(double a, double b, int n) { double c= (a+b)/2.0; double h3= abs(b-a)/6.0; double result= h3*(fk(a)+4.0*fk(c)+fk(b)); return result; } //********************************** double fk(double x) { return x * x; }



1Likes
LinkBack URL
About LinkBacks



