⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 8.6.cpp

📁 c入门代码大全
💻 CPP
字号:
/*用炫截法球方程f(x)=x3-5x2+16x-80=0的根*/
#include<stdio.h>
#include<math.h>
//int main()
float f(float x)
{
    float y;
    y=((x-5.0)*x+16.0)*x-80.0;
    return(y);
}
float xpoint (float x1,float x2)
{
      float y;
      y=(x1*f(x2)-x2*f(x1))/(f(x2)-f(x1));
      return(y);
}
float root(float x1,float x2)
{
      float x,y,y1;
      y1=f(x1);
      do
      {
          x=xpoint(x1,x2);
          y=f(x);
          if(y*y1>0)
          {
            y1=y;
            x1=x;
          }
          else
           x2=x;
      }while(fabs(y)>=0.0001);
      return(x);
}
  
   int main()
   {
       float x1,x2,f1,f2 ,x;
       do
       {
             printf("input x1,x2:\n");
             scanf("%f%f",&x1,&x2);
             f1=f(x1);
             f2=f(x2);
       }
       while(f1*f2>=0);
       x=root(x1,x2);
       printf("a root of equation is %f\n",x);
       getchar();
       getchar();
   }
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -