user-0 提问: 这个错误在哪   看了很久都没找到

回复:
user: user-1
content: 常量也有类型！ C++ Integer Constants Integer constants are constant data elements that have no fractional parts or exponents. They always begin with a digit. You can specify integer constants in decimal, octal, or hexadecimal form. They can specify signed or unsigned types and long or short types.  Syntax  integer-constant :  decimal-constant integer-suffixopt octal-constant integer-suffixopt hexadecimal-constant integer-suffixopt 'c-char-sequence'  decimal-constant :  nonzero-digit decimal-constant digit  octal-constant :  0 octal-constant octal-digit  hexadecimal-constant :  0x hexadecimal-digit 0X hexadecimal-digit hexadecimal-constant hexadecimal-digit  nonzero-digit : one of  1 2 3 4 5 6 7 8 9  octal-digit : one of  0 1 2 3 4 5 6 7  hexadecimal-digit : one of  0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F  integer-suffix :  unsigned-suffix long-suffixopt long-suffix unsigned-suffixopt  unsigned-suffix : one of  u U  long-suffix : one of  l L  64-bit integer-suffix :  i64  To specify integer constants using octal or hexadecimal notation, use a prefix that denotes the base. To specify an integer constant of a given integral type, use a suffix that denotes the type.  To specify a decimal constant, begin the specification with a nonzero digit. For example:  int i = 157;   // Decimal constant int j = 0198;  // Not a decimal number; erroneous octal constant int k = 0365;  // Leading zero specifies octal constant, not decimal  To specify an octal constant, begin the specification with 0, followed by a sequence of digits in the range 0 through 7. The digits 8 and 9 are errors in specifying an octal constant. For example:  int i = 0377;   // Octal constant int j = 0397;   // Error: 9 is not an octal digit  To specify a hexadecimal constant, begin the specification with 0x or 0X (the case of the “x” does not matter), followed by a sequence of digits in the range 0 through 9 and a (or A) through f (or F). Hexadecimal digits a (or A) through f (or F) represent values in the range 10 through 15. For example:  int i = 0x3fff;   // Hexadecimal constant int j = 0X3FFF;   // Equal to i  To specify an unsigned type, use either the u or U suffix. To specify a long type, use either the l or L suffix. For example:  unsigned uVal = 328u;             // Unsigned value long lVal = 0x7FFFFFL;            // Long value specified                                    //  as hex constant unsigned long ulVal = 0776745ul;  // Unsigned long value  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: 将较长的表达式拆为若干步较短的表达式并将其中间结果赋值给中间变量，每步占一行，方便调试。

user: user-2
content: s=1/2*(zk[j+1][k]-zk[j][k])*(xk[j][k]*zk[j+1][k]-xk[j+1][k]*zk[j][k])             *log((xk[j+1][k]*xk[j+1][k]+zk[j+1][k]*zk[j+1][k])/(xk[j][k]*xk[j][k]+             zk[j][k]*zk[j][k]))/(pow(zk[j+1][k]-zk[j][k],2)+pow(xk[j+1][k]-xk[j][k],2)             +(xk[j+1][k]-xk[j][k])*(xk[j][k]*zk[j+1][k]-xk[j+1][k]*zk[j][k])/             (pow(zk[j+1][k]-zk[j][k],2)+pow(xk[j+1][k]-xk[j][k],2))*(atan1(zk[j][k],xk[j][k]             )-atan1(zk[j+1][k],xk[j+1][k]))); 1)这个式子太长了 2） 1/2 =0  1/2*(zk[j+1][k]-zk[j][k])*(xk[j][k]*zk[j+1][k]-xk[j+1][k]*zk[j][k])             *log((xk[j+1][k]*xk[j+1][k]+zk[j+1][k]*zk[j+1][k])/(xk[j][k]*xk[j][k]+ 这一部分可以省掉了，结果为0 如果 不希望得到0 ;写成1.0/2* ........    引用 5 楼 zhao4zhong1 的回复:将较长的表达式拆为若干步较短的表达式并将其中间结果赋值给中间变量，每步占一行，方便调试。 ++  这一次，赵老师，言简意赅，切中要害，不过标点太少，看着困难。

user: user-3
content: for(j=0;j<n+1;j++)  兄台，这是7次循环，确定需要的7次而不是6次？

user: user-0
content: 引用 1 楼 user-4 的回复:for(j=0;j<n+1;j++) { /*这个地方出问题*/ s=1/2*(zk[j+1][k]-zk[j][k])*(xk[j][k]*zk[j+1][k]-xk[j+1][k]*zk[j][k])             *log((xk[j+1][k]*xk[j+1][k]+zk[j+1][k]*zk[j+1][k])/(xk[j][k]*xk[j][k]+             zk[j][k]*zk[j][k]))/(pow(zk[j+1][k]-zk[j][k],2)+pow(xk[j+1][k]-xk[j][k],2)             +(xk[j+1][k]-xk[j][k])*(xk[j][k]*zk[j+1][k]-xk[j+1][k]*zk[j][k])/             (pow(zk[j+1][k]-zk[j][k],2)+pow(xk[j+1][k]-xk[j][k],2))*(atan1(zk[j][k],xk[j][k]             )-atan1(zk[j+1][k],xk[j+1][k])));             s1=+s; }  以上循环执行到j为6时，zk[j+1][k]、xk[j][k]等越界了。LZ要确认究竟是需要for(j=0;j<n+1;j++)还是for(j=0;j<n;j++)？如果是后者则不会越界，如果是前者，则需要增大zk、xk等;  谢谢  只需要执行6次  关键是计算出的值都是0

user: user-0
content: 引用 2 楼 my_live_123 的回复:  for(j=0;j<n+1;j++)  兄台，这是7次循环，确定需要的7次而不是6次？ 嗯   是六次   但是计算出的值都是0 啊

user: user-4
content: for(j=0;j<n+1;j++) { /*这个地方出问题*/ s=1/2*(zk[j+1][k]-zk[j][k])*(xk[j][k]*zk[j+1][k]-xk[j+1][k]*zk[j][k])             *log((xk[j+1][k]*xk[j+1][k]+zk[j+1][k]*zk[j+1][k])/(xk[j][k]*xk[j][k]+             zk[j][k]*zk[j][k]))/(pow(zk[j+1][k]-zk[j][k],2)+pow(xk[j+1][k]-xk[j][k],2)             +(xk[j+1][k]-xk[j][k])*(xk[j][k]*zk[j+1][k]-xk[j+1][k]*zk[j][k])/             (pow(zk[j+1][k]-zk[j][k],2)+pow(xk[j+1][k]-xk[j][k],2))*(atan1(zk[j][k],xk[j][k]             )-atan1(zk[j+1][k],xk[j+1][k])));             s1=+s; }  以上循环执行到j为6时，zk[j+1][k]、xk[j][k]等越界了。LZ要确认究竟是需要for(j=0;j<n+1;j++)还是for(j=0;j<n;j++)？如果是后者则不会越界，如果是前者，则需要增大zk、xk等;