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

  1. /*                     if1.c
  2.  *
  3.  *   Synopsis  - A decimal integer is input, added to CONSTANT, 
  4.  *               and the sum is displayed. If the sum is less 
  5.  *               than 20, a message is issued.
  6.  *
  7.  *   Objective - Illustrates the simplest form of the if statement
  8.  */
  9.  
  10. /* Include Files */
  11. #include <stdio.h> 
  12.  
  13. /* Constant Definitions */
  14. #define CONSTANT 5
  15.  
  16. /* Function Prototypes */
  17. int add_const( int intvar, int constant );
  18. /*   PRECONDITION:  intvar and constant are integers
  19.  *
  20.  *   POSTCONDITION: The value returned is the sum of its parameter, 
  21.  *                  intvar and constant
  22.  */
  23.  
  24. int main( void )
  25. {
  26.      int sum, intvar;
  27.  
  28.      printf( "Enter a decimal integer: " );
  29.      scanf( "%d", &intvar );
  30.  
  31.      sum = add_const( intvar, CONSTANT );
  32.      printf( "%d + %d is %d.\n", intvar, CONSTANT, sum );
  33.  
  34.      if ( sum < 20 )               /* Notes 1 and 2 */
  35.           printf( "The number is small enough.\n" );
  36.      return 0;
  37. }
  38.  
  39. /*******************************add_const()*********************/
  40.  
  41. int add_const( int intvar, int constant )
  42. {
  43.      return( intvar + constant );
  44.