回覆列表
  • 1 # 木子李ovo

    #include <stdio.h>

    #include <math.h>

    float ff(float x)

    {

    return x*(x*x-2)-5;

    }

    float Secant(float x0,float x1)

    {

    return (x1 - (ff(x1)*(x1-x0))/(ff(x1)-ff(x0)));

    }

    void main()

    {

    int number,k=2;

    float x0=2,x1=2.2,x2;

    printf("x[0] = %.4f, x[1] = %.4f, ",x0,x1);

    while (1)

    {

    if (fabs(x0-x1)<1e-4) break;

    x2 = Secant(x0,x1);

    x0 = x1;

    x1 = x2;

    printf("x[%d] = %.4f, ",k,x2);

    k++;

    if (k%3==0) printf("\n");

    }

    if (k%3!=0) printf("\n");

    printf("iteration times: %d, roots: %.4f\n ",k-2,x1);

    return;

    }

  • 2 # 圓臉講娛樂

    #include <stdio.h>

    #include <math.h>

    float ff(float x)

    {

    return x*(x*x-2)-5;

    }

    float Secant(float x0,float x1)

    {

    return (x1 - (ff(x1)*(x1-x0))/(ff(x1)-ff(x0)));

    }

    void main()

    {

    int number,k=2;

    float x0=2,x1=2.2,x2;

    printf("x[0] = %.4f, x[1] = %.4f, ",x0,x1);

    while (1)

    {

    if (fabs(x0-x1)<1e-4) break;

    x2 = Secant(x0,x1);

    x0 = x1;

    x1 = x2;

    printf("x[%d] = %.4f, ",k,x2);

    k++;

    if (k%3==0) printf("\n");

    }

    if (k%3!=0) printf("\n");

    printf("iteration times: %d, roots: %.4f\n ",k-2,x1);

    return;

    }

  • 中秋節和大豐收的關聯?
  • 正常嘛?98年的女生開始想著結婚生孩子,天天在家帶孩子玩不用上班?