Что не так с этим кодом? Вычисление площади под кривой полинома (ax2 +bx +c)
#include <stdio.h> #include <math.h> int compute_polynomial (int a, int b, int c, int x){ //prototype int fx; fx = a* pow(x,2) + b*x + c ; return (fx); } double trapezoid_area (int x1, int x2, int fx1, int fx2){ //prototype double area; area = (fx1 + fx2)* (x2-x1) / 2; return (area); } double auc_polinomial (int a, int b, int c, int partitions, int x_low, int x_high) { //prototype double total_area = 0; int x1, x2, one_partition; int fx1, fx2; double trap_area; one_partition = (x_high - x_low)/ partitions; for (x1 = x_low; x1<=x_high; x1 += one_partition){ fx1= compute_polynomial (a, b, c, x1); for (x2= x_low + one_partition; x2<=x_high; x2 += one_partition){ fx2= compute_polynomial (a, b ,c, x2); } trap_area = trapezoid_area (x1,x2, fx1, fx2); total_area += trap_area; } return (total_area); } int main (){ int a,b,c; int x_low, x_high; int partitions; double total_area; printf("Enter three polinomial coefficents in order a b c : "); scanf("%d %d %d", &a, &b, &c); printf("Enter x interval: "); scanf("%d %d", &x_low, &x_high); printf("Enter number of partitions: "); scanf("%d", &partitions); total_area = auc_polinomial( a, b, c, partitions, x_low, x_high); printf(" AUC: %f", total_area); return (0); }
Что я уже пробовал:
Я уже выполнил его, но результат AUC не появляется на экране. Я просто знаю, что что-то не так с циклом "for", когда я компилирую общую площадь.