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;
    }


     

  • 相关阅读:
    [转] DataSet的的几种遍历
    [转] C#实现在Sql Server中存储和读取Word文件 (Not Correct Modified)
    C# 在根据窗体中的表格数据生成word文档时出错
    【剑指offer】堆栈推弹出序列
    kettle于javascript步骤错误处理
    【算法导论】堆排序
    malloc,free简单的实现
    Lichee (六) 优化配置的微内核
    EJBCA于Linux安装在
    【C++】智能指针auto_ptr简单的实现
  • 原文地址:https://www.cnblogs.com/2014acm/p/3902535.html
Copyright © 2011-2022 走看看