您的位置:首页 > 其它

函数调用解析

2016-10-10 22:31 92 查看
程序中,主要在于调用函数和函数定义之间必须相互吻合!

/*****************************************************

copyright (C), 2014-2015, Lighting Studio. Co.,     Ltd.

File name:

Author:Jerey_Jobs    Version:0.1    Date:

Description:

Funcion List:

*****************************************************/

#include <stdio.h>

#include <math.h>

float f(float x);

float xpoint(float x1,float x2);

float root(float x1,float x2);

int main()

{

    float x1,x2,y1,y2,x,y;

 do

 {

     printf("请输入两个x1和x2...\n");

     scanf("%f,%f",&x1,&x2);

 }while(f(x1)*f(x2)>=0);

 x=root(x1,x2);

    printf("答案是%f\n",x);

    return 0;

}

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

 x=(x1*f(x2)-x2*f(x1))/(f(x2)-f(x1));

 return x;

}

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.000001);

 return x;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: