user-0 提问: 函数的！苦逼自学党！ 求帮忙！谢谢！

回复:
user: user-1
content: mk:@MSITStore:C:\MSDN98\98VS\2052\vclang.chm::/html/_pluslang_c.2b2b_.floating.2d.point_constants.htm C++ Floating-Point Constants Floating-point constants specify values that must have a fractional part. These values contain decimal points (.) and can contain exponents.  Syntax  floating-constant :  fractional-constant exponent-partopt floating-suffixopt digit-sequence exponent-part floating-suffixopt  fractional-constant :  digit-sequenceopt . digit-sequence digit-sequence .  exponent-part :  e signopt digit-sequence E signopt digit-sequence  sign : one of  + –  digit-sequence :  digit digit-sequence digit  floating-suffix :one of  f l F L  Floating-point constants have a “mantissa,” which specifies the value of the number, an “exponent,” which specifies the magnitude of the number, and an optional suffix that specifies the constant’s type. The mantissa is specified as a sequence of digits followed by a period, followed by an optional sequence of digits representing the fractional part of the number. For example:  18.46 38.  The exponent, if present, specifies the magnitude of the number as a power of 10, as shown in the following example:  18.46e0      // 18.46 18.46e1      // 184.6  If an exponent is present, the trailing decimal point is unnecessary in whole numbers such as 18E0.  Floating-point constants default to type double. By using the suffixes f or l (or F or L — the suffix is not case sensitive), the constant can be specified as float or long double, respectively.  Although long double and double have the same representation, they are not the same type. For example, you can have overloaded functions like  void func( double );  and   void func( long double );

user: user-1
content: 查MSDN是Windows程序员必须掌握的技能之一。 mk:@MSITStore:C:\MSDN98\98VS\2052\vccore.chm::/html/_crt_fabs.htm fabs Calculates the absolute value of the floating-point argument.  double fabs( double x );  Function Required Header Compatibility  fabs <math.h> ANSI, Win 95, Win NT    For additional compatibility information, see Compatibility in the Introduction.  Libraries  LIBC.LIB Single thread static library, retail version  LIBCMT.LIB Multithread static library, retail version  MSVCRT.LIB Import library for MSVCRT.DLL, retail version    Return Value  fabs returns the absolute value of its argument. There is no error return.  Parameter  x  Floating-point value  Example  /* ABS.C: This program computes and displays  * the absolute values of several numbers.  */  #include  <stdio.h> #include  <math.h> #include  <stdlib.h>  void main( void ) {    int    ix = -4, iy;    long   lx = -41567L, ly;    double dx = -3.141593, dy;     iy = abs( ix );    printf( "The absolute value of %d is %d\n", ix, iy);     ly = labs( lx );    printf( "The absolute value of %ld is %ld\n", lx, ly);     dy = fabs( dx );    printf( "The absolute value of %f is %f\n", dx, dy ); }   Output  The absolute value of -4 is 4 The absolute value of -41567 is 41567 The absolute value of -3.141593 is 3.141593   Floating-Point Support Routines  See Also   abs, _cabs, labs

user: user-2
content: 楼主得学会自己找资料、自己调试代码、自己查错误。当然刚开始可能有点难，代码写多了慢慢就会了。

user: user-2
content: 这里的公式和方程我都不懂，但是我把这一行的括号挪了个位置，就输出5.0000了，不知道这样对不对     y = (x1*f(x2)) - x2*f(x1) / (f(x2)-f(x1)); 改成     y = (x1*f(x2) - x2*f(x1)) / (f(x2)-f(x1));

user: user-2
content: vc6.0和TC都是老掉牙的东西了，尽量远离。  fabs是math.h里的函数，求绝对值的。这种问题楼主要学会自己查手册或者google，总这么提问不是办法。 while (fabs (y) >= 1E-6);  实际上相当于 while(y!=0)，但是浮点数的二进制表示有误差，不能直接与0比较，所以只要它的绝对值大于0.000001就认为不是0 参考：http://bbs.csdn.net/topics/80345307  “中间就改了一下”很可能就会造成问题，只能想办法调试，或者和书上的代码对比分析