⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex05_03.c

📁 C程序设计经典教程第5版程序示例,比较适合初级c语言的学生
💻 C
字号:
/* ex05_03.c */
/* Testing the math library functions */
#include <stdio.h>
#include <math.h>

/* function main begins program execution */
int main( void )
{
   /* calculates and outputs the square root */
   printf( "sqrt(%.1f) = %.1f\n", 900.0, sqrt( 900.0 ) );
   printf( "sqrt(%.1f) = %.1f\n", 9.0, sqrt( 9.0 ) );
   
   /* calculates and outputs the exponential function e to the x */
   printf( "exp(%.1f) = %f\n", 1.0, exp( 1.0 ) );
   printf( "exp(%.1f) = %f\n", 2.0, exp( 2.0 ) );
   
   /* calculates and outputs the logorithm (base e) */
   printf( "log(%f) = %.1f\n", 2.718282, log( 2.718282 ) );
   printf( "log(%f) = %.1f\n", 7.389056, log( 7.389056 ) );
   
   /* calculates and outputs the logorithm (base 10) */
   printf( "log10(%.1f) = %.1f\n", 1.0, log10( 1.0 ) );
   printf( "log10(%.1f) = %.1f\n", 10.0, log10( 10.0 ) );
   printf( "log10(%.1f) = %.1f\n", 100.0, log10( 100.0 ) );
   
   /* calculates and outputs the absolute value */
   printf( "fabs(%.1f) = %.1f\n", 13.5, fabs( 5.0 ) );
   printf( "fabs(%.1f) = %.1f\n", 0.0, fabs( 0.0 ) );
   printf( "fabs(%.1f) = %.1f\n", -13.5, fabs( -5.0 ) );
   
   /* calculates and outputs ceil( x ) */
   printf( "ceil(%.1f) = %.1f\n", 9.2, ceil( 9.2 ) );
   printf( "ceil(%.1f) = %.1f\n", -9.8, ceil( -9.8 ) );
   
   /* calculates and outputs floor( x ) */
   printf( "floor(%.1f) = %.1f\n", 9.2, floor( 9.2 ) );
   printf( "floor(%.1f) = %.1f\n", -9.8, floor( -9.8 ) );
   
   /* calculates and outputs pow( x, y ) */
   printf( "pow(%.1f, %.1f) = %.1f\n", 2.0, 7.0, pow( 2.0, 7.0 ) );
   printf( "pow(%.1f, %.1f) = %.1f\n", 9.0, 0.5, pow( 9.0, 0.5 ) );
   
   /* calculates and outputs fmod( x, y ) */
   printf( "fmod(%.3f/%.3f) = %.3f\n", 13.675, 2.333, 
           fmod( 13.675, 2.333 ) );

   /* calculates and outputs sin( x ) */
   printf( "sin(%.1f) = %.1f\n", 0.0, sin( 0.0 ) );
   
   /* calculates and outputs cos( x ) */
   printf( "cos(%.1f) = %.1f\n", 0.0, cos( 0.0 ) );
   
   /* calculates and outputs tan( x ) */
   printf( "tan(%.1f) = %.1f\n", 0.0, tan( 0.0 ) );
   
   return 0; /* indicates successful termination */

} /* end main */


/**************************************************************************
 * (C) Copyright 1992-2007 by Deitel & Associates, Inc. and               *
 * Pearson Education, Inc. All Rights Reserved.                           *
 *                                                                        *
 * DISCLAIMER: The authors and publisher of this book have used their     *
 * best efforts in preparing the book. These efforts include the          *
 * development, research, and testing of the theories and programs        *
 * to determine their effectiveness. The authors and publisher make       *
 * no warranty of any kind, expressed or implied, with regard to these    *
 * programs or to the documentation contained in these books. The authors *
 * and publisher shall not be liable in any event for incidental or       *
 * consequential damages in connection with, or arising out of, the       *
 * furnishing, performance, or use of these programs.                     *
 *************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -