home *** CD-ROM | disk | FTP | other *** search
/ C by Discovery (4th Edition) / C_By_Discovery_4th_Edition.tar / C_By_Discovery_4th_Edition / _DISK_ / ch3 / circle.c < prev    next >
C/C++ Source or Header  |  2005-06-16  |  2KB  |  65 lines

  1. /*                                circle.c
  2.  *
  3.  *   Synopsis  - Accepts input of the radius of a circle and 
  4.  *               displays the area and circumference.
  5.  *
  6.  *   Objective - To illustrate the declaration and use of 
  7.  *               functions with type other than int.
  8.  */
  9.  
  10. /* Include Files */
  11. #include <stdio.h>
  12.  
  13. /* Constant Definitions */
  14. #define PI 3.1415926
  15.  
  16. /* Function Prototypes */
  17. double area( double r );                         /* Note 1 */
  18. /* PRECONDITION:  r can be any positive real number.
  19.  *
  20.  * POSTCONDITION: Calculates the area of a circle given its radius. 
  21.  */
  22.  
  23. double circumference( double r );
  24. /* PRECONDITION:  r can be any positive real number.
  25.  *
  26.  * POSTCONDITION: Calculates the circumference of a circle given its 
  27.  *                radius. 
  28.  */
  29.  
  30.  
  31. int main( void )
  32. {
  33.      double radius;
  34.  
  35.      printf( "Program to calculate area and circumference " );
  36.      printf( "of a circle.\n" );
  37.      printf( "------- -- --------- ---- --- ------------- " );
  38.      printf( "-- - -------\n" );
  39.  
  40.      printf( "Please enter the radius : " );
  41.      scanf ( "%lf", &radius );
  42.  
  43.      printf( "A circle with radius %5.2f has area %5.2f.\n",
  44.                                         radius, area( radius ) );
  45.      printf( "The circumference of the circle is %5.2f.\n",
  46.                                         circumference( radius ) );
  47.      return 0;
  48. }
  49.  
  50. /*******************************area()**************************/
  51.  
  52. double area( double r )                          /* Note 2 */
  53. {
  54.      return( PI*r*r );
  55. }
  56.  
  57. /*******************************circumference()*****************/
  58.  
  59. double circumference( double r )                 /* Note 2 */
  60. {
  61.      return( 2*PI*r );
  62. }
  63.  
  64.  
  65.