zoukankan      html  css  js  c++  java
  • 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
    ",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 ",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
    ",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 ",x);
        return 0;
    }


     

  • 相关阅读:
    我理解的朴素贝叶斯模型
    P2P贷款全攻略,贷前、贷中、贷后工作事项解析
    Jupyter Notebook 快速入门
    R语言|数据特征分析
    R语言︱处理缺失数据&&异常值检验、离群点分析、异常值处理
    mysql explain执行计划详解
    R语言中的回归诊断-- car包
    一行代码搞定 R 语言模型输出!(使用 stargazer 包)
    基于R语言的时间序列指数模型
    基于R语言的ARIMA模型
  • 原文地址:https://www.cnblogs.com/2014acm/p/3902535.html
Copyright © 2011-2022 走看看