Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- float fn(float coeff[], float size, float x)
- {
- float result = 0;
- int i=0;
- for(i = 0; i < size; i++)
- {
- result += coeff[i];
- result *= x;
- }
- result += coeff[i];
- return 0;
- }
- int main()
- {
- int i,n;
- int degree;
- printf("Enter the degree: ");
- scanf("%d", °ree);
- float coeff[degree + 1];
- printf("Enter the %d coefficients: ",degree + 1);
- for(i = 0; i < degree + 1; i++)
- {
- scanf("%f", &coeff[i]);
- }
- float a, b, s = 0, y = 0, h;
- printf("Enter the no of interval =");
- scanf("%d", &n);
- printf("Enter the lower limit=");
- scanf("%f", &a);
- printf("Enter the upper limit=");
- scanf("%f", &b);
- h = (b - a) / n;
- for(i = 1 ; i <= n - 1; i++)
- {
- s = s + fn(coeff, degree, a + i * h);
- }
- y = (fn(coeff, degree, a) + fn(coeff, degree, b) + 2 * s) * h / 2;
- printf("the value of y is = %f", y);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement