1 条题解

  • 0
    @ 2025-4-7 21:28:47

    C :

    #include<stdio.h>
    #include<math.h>
    float solve(float a,float b,float c,float d,float x);
    
    int main()
    {
    	float a,b,c,d,k;
    	scanf("%f%f%f%f%f",&a,&b,&c,&d,&k);
    	printf("%.4f\n",solve(a,b,c,d,k));
    	return 0;
    }
    
    float solve(float a,float b,float c,float d,float x)
    {
    	while(fabs(a*x*x*x+b*x*x+c*x+d)>0.000001)
    	{
    		x=x-(a*x*x*x+b*x*x+c*x+d)/(3*a*x*x+2*b*x+c);
    	}
    		return x;
    }
    

    C++ :

    #include <stdio.h>
    #include <math.h>
    int main() {
    	float solve(float a, float b, float c, float d, float x);
    	float a, b, c, d, k;
    	scanf("%f%f%f%f%f", &a, &b, &c, &d, &k);
    	printf("%.4f\n", solve(a, b, c, d, k));
    	return 0;
    }
    float solve(float a, float b, float c, float d, float x) {
    	while (fabs(a * x * x * x + b * x * x + c * x + d) > 1e-6) {
    		x = x - (a * x * x * x + b * x * x + c * x + d) / (3 * a * x * x + 2 * b * x + 3 * c);
    	}
    	return x;
    }
    
    

    Pascal :

    
    
    var 
      a,b,c,d,k:double; //全局
    
    function solve():double;
    var x:double;
    begin
      x:=k;
      while( abs(a*x*x*x+b*x*x+c*x+d)>1e-6 ) do
        x:=x-(a*x*x*x+b*x*x+c*x+d)/(3*a*x*x+2*b*x+3*c);
      solve:=x;
    end;
    
    begin
      readln(a,b,c,d,k);
      writeln( solve():0:4 );
    end.
    
    
    
    
    
    
    
    • 1

    信息

    ID
    1333
    时间
    1000ms
    内存
    32MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者