错误:无效后缀";x";关于浮动常数 #包括 #包括 #包括 #定义ESP 0.0001 #定义F(x)x^3-2.5x^2-1.8x+2.356 void main() { 浮点数x0,x1,x2,f1,f2,f0; 整数计数=0; 做 { printf(“\n输入x0:”的值); scanf(“%f”、&x0); }而(F(x0)>0); 做 { printf(“\n输入x1:”的值); scanf(“%f”和&x1); }而(F(x1)2.5*x*x您认为是什么?并且没有“隐式*”…例如1.8x使用:#定义F(x)((x)*(x)*(x)-2.5*(x)*(x)-1.8*(x)+2.356)。请注意,它们的使用很重要,因为宏只是文本替换。虽然我很想使用这些代码,但我不知道该放在哪里。 #include <stdio.h> #include <conio.h> #include <math.h> #define ESP 0.0001 #define F(x) x^3-2.5x^2-1.8x+2.356 void main() { float x0,x1,x2,f1,f2,f0; int count=0; do { printf("\nEnter the value of x0: "); scanf("%f",&x0); }while(F(x0) > 0); do { printf("\nEnter the value of x1: "); scanf("%f",&x1); }while(F(x1) < 0); printf("\n__________________________________________________________\n"); printf("\n x0\t x1\t x2\t f0\t f1\t f2"); printf("\n__________________________________________________________\n"); do { f0=F(x0); f1=F(x1); x2=x0-((f0*(x1-x0))/(f1-f0)); f2=F(x2); printf("\n%f %f %f %f %f %f",x0,x1,x2,f0,f1,f2); if(f0*f2<0) { x1=x2; } else { x0 = x2; } }while(fabs(f2)>ESP); printf("\n__________________________________________________________\n"); printf("\n\nApp.root = %f",x2); getch(); } float F(float x) { return x * x * x + 2.5f * x * x + 1.8f * x + 2.356f; }

错误:无效后缀";x";关于浮动常数 #包括 #包括 #包括 #定义ESP 0.0001 #定义F(x)x^3-2.5x^2-1.8x+2.356 void main() { 浮点数x0,x1,x2,f1,f2,f0; 整数计数=0; 做 { printf(“\n输入x0:”的值); scanf(“%f”、&x0); }而(F(x0)>0); 做 { printf(“\n输入x1:”的值); scanf(“%f”和&x1); }而(F(x1)2.5*x*x您认为是什么?并且没有“隐式*”…例如1.8x使用:#定义F(x)((x)*(x)*(x)-2.5*(x)*(x)-1.8*(x)+2.356)。请注意,它们的使用很重要,因为宏只是文本替换。虽然我很想使用这些代码,但我不知道该放在哪里。 #include <stdio.h> #include <conio.h> #include <math.h> #define ESP 0.0001 #define F(x) x^3-2.5x^2-1.8x+2.356 void main() { float x0,x1,x2,f1,f2,f0; int count=0; do { printf("\nEnter the value of x0: "); scanf("%f",&x0); }while(F(x0) > 0); do { printf("\nEnter the value of x1: "); scanf("%f",&x1); }while(F(x1) < 0); printf("\n__________________________________________________________\n"); printf("\n x0\t x1\t x2\t f0\t f1\t f2"); printf("\n__________________________________________________________\n"); do { f0=F(x0); f1=F(x1); x2=x0-((f0*(x1-x0))/(f1-f0)); f2=F(x2); printf("\n%f %f %f %f %f %f",x0,x1,x2,f0,f1,f2); if(f0*f2<0) { x1=x2; } else { x0 = x2; } }while(fabs(f2)>ESP); printf("\n__________________________________________________________\n"); printf("\n\nApp.root = %f",x2); getch(); } float F(float x) { return x * x * x + 2.5f * x * x + 1.8f * x + 2.356f; },c,C,程序似乎无法将#define F(x)x^3-2.5x^2-1.8x+2.356作为函数读取,但当我使用#define F(x)3*(x)-1-cos(x)时,没有错误 我试过定义F(x)(x)^3-2.5(x)^2-1.8(x)+2.356,运气不好 F(x)x^3-2.5x^2-1.8x+2.356 ^不是C use pow()中的幂运算符,powf()函数(但在本例中不需要它) 2.5x必须是2.5*x——买一本关于C的书 不要定义函数,让它们成为“真正的”函数 在浮点表达式中不要使用双字

程序似乎无法将
#define F(x)x^3-2.5x^2-1.8x+2.356
作为函数读取,但当我使用
#define F(x)3*(x)-1-cos(x)
时,没有错误

我试过定义F(x)(x)^3-2.5(x)^2-1.8(x)+2.356,运气不好

F(x)x^3-2.5x^2-1.8x+2.356

  • ^不是C use pow()中的幂运算符,powf()函数(但在本例中不需要它)
  • 2.5x必须是2.5*x——买一本关于C的书
  • 不要定义函数,让它们成为“真正的”函数
  • 在浮点表达式中不要使用双字面值


  • ^
    是XOR运算符。同样
    2.5x^2
    -->
    2.5*x*x
    您认为是什么?并且没有“隐式
    *
    ”…例如
    1.8x
    使用:
    #定义F(x)((x)*(x)*(x)-2.5*(x)*(x)-1.8*(x)+2.356)
    。请注意,它们的使用很重要,因为宏只是文本替换。虽然我很想使用这些代码,但我不知道该放在哪里。
    #include <stdio.h>
    #include <conio.h>
    #include <math.h>
    #define ESP 0.0001
    #define F(x) x^3-2.5x^2-1.8x+2.356
    void main()
    {
      float x0,x1,x2,f1,f2,f0;
      int count=0;
    
      do
      {
      printf("\nEnter the value of x0: ");
      scanf("%f",&x0);
      }while(F(x0) > 0);
      do
      {
      printf("\nEnter the value of x1: ");
      scanf("%f",&x1);
      }while(F(x1) < 0);
      printf("\n__________________________________________________________\n");
      printf("\n    x0\t       x1\t x2\t   f0\t   f1\t   f2");
      printf("\n__________________________________________________________\n");
      do
      {
      f0=F(x0);
      f1=F(x1);
      x2=x0-((f0*(x1-x0))/(f1-f0));
      f2=F(x2);
      printf("\n%f %f %f %f %f %f",x0,x1,x2,f0,f1,f2);
      if(f0*f2<0)
       {
        x1=x2;
       }
       else
       {
        x0 = x2;
       }
      }while(fabs(f2)>ESP);
    printf("\n__________________________________________________________\n");
    printf("\n\nApp.root = %f",x2);
    getch();
    }
    
    float F(float x)
    {
      return x * x * x + 2.5f * x * x + 1.8f * x + 2.356f;
    }