求函数的导数。// 对 3.25x^3 - 2.75x^2 5.16x 1 求导 #include stdio.h #include math.h // 定义多项式的单项式结构体 typedef struct { double coeff; // 系数 int exp; // 指数 } Term; double ployn(double a[], double x, int degree); int main() { // 数组中记录多项式的各项(系数和指数) Term poly[] { {3.75, 4}, {3.25, 3}, {-2.75, 2}, {5.16, 1}, {1.0, 0} }; int i, n sizeof(poly) / sizeof(poly[0]); int degree poly[0].exp - 1; double coeff[degree1], x; for(i0; i degree; i) coeff[i] 0; printf(3.75x^4 3.25x^3 - 2.75x^2 5.16x 1的导数:\n); for (i 0; i n; i) { // 常数项直接跳过 if (poly[i].exp 0) continue; // 新系数新指数 double new_coeff poly[i].coeff * poly[i].exp; int new_exp poly[i].exp - 1; coeff[new_exp] new_coeff; // 格式化输出处理正负号和首项 if (i new_coeff 0) printf(); if (i new_coeff 0) printf(-); // 指数为0 if (new_exp 0) printf( %.2f , fabs(new_coeff)); // 指数为1 else if (new_exp 1) printf( %.2fx , fabs(new_coeff)); else printf( %.2fx^%d , fabs(new_coeff), new_exp); } printf(\n系数是:); for(i 0; i degree; i) printf(%.2f , coeff[i]); x 1.25; printf(\nf(%.2f) %.4f\n, x, ployn(coeff, x, degree)1e-9); return 0; } double ployn(double a[], double x, int degree) { int i; int limit degree - 1; double sum1 a[0], sum2 0; double xpwr1 x, xpwr2 x * x; for(i 1; i limit; i 2) { sum1 a[i] * xpwr1; xpwr1 * x * x; sum2 a[i1] * xpwr2; xpwr2 * x * x; } for( ; i degree; i) sum1 a[i] * xpwr1; return sum1 sum2; }3.75x^4 3.25x^3 - 2.75x^2 5.16x 1的导数:15.00x^3 9.75x^2 - 5.50x 5.16系数是:5.16 -5.50 9.75 15.00f(1.25) 42.8163