rwkj 1309

#include <stdio.h>
int main()
{
    float a,b,c,d,x,y,max,min;
    max=10;
    min=-10;    
    scanf("%f%f%f%f",&a,&b,&c,&d);
    {
        x=(max+min)/2;
        y=a*x*x*x+b*x*x+c*x+d;
        while(y!=0)
        {
            y=a*x*x*x+b*x*x+c*x+d;
            
            if(y>0)
            {    max=x;
              x=(x+min)/2;
            }
            
            if(y<0)
            {    min=x;
              x=(x+max)/2;
            }
        }
        printf("%.3f",x);
    }
}
View Code

 

#include <stdio.h>
int main()
{
    float a,b,c,d,x,y,max,min;
    max=10;
    min=-10;   
    scanf("%f%f%f%f",&a,&b,&c,&d);
    {
        x=(max+min)/2;
        y=a*x*x*x+b*x*x+c*x+d;
        while(y!=0)
        {
            y=a*x*x*x+b*x*x+c*x+d;
           
            if(y>0)
            {    max=x;
              x=(x+min)/2;                        //此时min不变    x----新max   ======再赋值  得到 新x
   }
   
            if(y<0)
            {    min=x;
              x=(x+max)/2;
   }
        }
        printf("%.3f",x);
    }
}


 

 

 

#include<stdio.h>
main()
{     
    float a,b,c,d,i,j,k,m=-10.,n=10.,x;;
    scanf("%f%f%f%f",&a,&b,&c,&d);
    do
    {
        x=(m+n)/2;
        i=a*m*m*m+b*m*m+c*m+d;
        j=a*n*n*n+b*n*n+c*n+d;
        k=a*x*x*x+b*x*x+c*x+d;
        if((i<=0&&0<=k)||(k<=0&&0<=i))
        {n=x;}
        if((j<=0&&0<=k)||(k<=0&&0<=j))
        {m=x;}
    }while(k!=0);
    
    printf("%.3f\n",x);    
}
View Code

#include<stdio.h>
main()
{    
    float a,b,c,d,i,j,k,m=-10.,n=10.,x;;
    scanf("%f%f%f%f",&a,&b,&c,&d);
    do
    {
        x=(m+n)/2;
        i=a*m*m*m+b*m*m+c*m+d;
        j=a*n*n*n+b*n*n+c*n+d;
        k=a*x*x*x+b*x*x+c*x+d;
        if((i<=0&&0<=k)||(k<=0&&0<=i))
        {n=x;}
        if((j<=0&&0<=k)||(k<=0&&0<=j))
        {m=x;}
    }while(k!=0);
   
    printf("%.3f\n",x);   
}

 

 

#include <stdio.h>
#include <math.h>
int main()
{
    float a,b,c,d,x1,x2,x,fx1,fx2,fx;
    scanf("%f%f%f%f",&a,&b,&c,&d);
    x1=-10; x2=10;  
    fx1=a*x1*x1*x1+b*x1*x1+c*x1+d;
    fx2=a*x2*x2*x2+b*x2*x2+c*x2+d;      
    do {
        x=(x1+x2)/2;
        fx=a*x*x*x+b*x*x+c*x+d;
        if (fx*fx1<0) { x2=x; fx2=fx; }
        else {  x1=x; fx1=fx;}
    } while (fabs(fx)>=1e-5);         
    printf("%.3f\n",x);
    return 0;
}
View Code

#include <stdio.h>
#include <math.h>
int main()
{
    float a,b,c,d,x1,x2,x,fx1,fx2,fx;
    scanf("%f%f%f%f",&a,&b,&c,&d);
    x1=-10; x2=10; 
    fx1=a*x1*x1*x1+b*x1*x1+c*x1+d;
    fx2=a*x2*x2*x2+b*x2*x2+c*x2+d;     
    do {
        x=(x1+x2)/2;
        fx=a*x*x*x+b*x*x+c*x+d;
        if (fx*fx1<0) { x2=x; fx2=fx; }
        else {  x1=x; fx1=fx;}
    } while (fabs(fx)>=1e-5);        
    printf("%.3f\n",x);
    return 0;
}


 

 

posted @ 2014-08-10 11:07  2014acm  阅读(96)  评论(0编辑  收藏  举报