if (表达式) 语句 1 [ else 语句2 ]
// 递归函数 power() 计算浮点数的整数次方 // ----------------------------------------- double power( double base, unsigned int exp ) { if ( exp == 0 ) return 1.0; else return base * power( base, exp-1 ); }
if ( n > 0 ) if ( n % 2 == 0 ) puts( "n is positive and even"); else // 与最后一个 if 匹配 puts( "n is positive and odd" );
if ( n > 0 ) { if ( n % 2 == 0 ) puts( "n is positive and even" ); } else // 与第一个 if 匹配 puts( "n is negative or zero" );
// 计算测量值的误差 // -------------------------------- double spec = 10.0, measured = 10.3, diff; /* ... */ diff = measured - spec; if ( diff >= 0.0 && diff < 0.5 ) printf( "Upward deviation: %.2f\n", diff ); else if ( diff < 0.0 && diff > -0.5 ) printf( "Downward deviation: %.2f\n", diff ); else printf( "Deviation out of tolerance!\n" );
本文链接:http://task.lmcjl.com/news/15498.html