home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0000 - 0009 / ibm0000-0009 / ibm0003.tar / ibm0003 / LCNOW2.ZIP / EXAMPLES / ADD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-06-21  |  927 b   |  54 lines

  1. /*
  2.  * A D D
  3.  *
  4.  * This program demonstrates the use of functions
  5.  * to perform calculations.  A separate function is
  6.  * needed for each data type.
  7.  */
  8.  
  9.  
  10. /*
  11.  * AddIntegers()
  12.  *
  13.  * This function takes two integer arguments
  14.  * and returns their sum in a long integer.
  15.  */
  16. long
  17. AddIntegers(int number1, int number2)
  18. {
  19.     long total;
  20.     total = (long)number1 + (long)number2;
  21.     return (total);
  22. }
  23.  
  24.  
  25. /*
  26.  * AddReals()
  27.  *
  28.  * This function takes two float arguments
  29.  * and returns their sum in a double.
  30.  */
  31. double
  32. AddReals(float number1, float number2)
  33. {
  34.     double total;
  35.     total = (double)number1 + (double)number2;
  36.     return (total);
  37. }
  38.  
  39.  
  40. int
  41. main(void)
  42. {
  43.     int n1 = 20, n2 = 25;
  44.     float f1 = 12.34, f2 = 56.78;
  45.  
  46.     /* Add two integers. */
  47.     printf("%d + %d = %ld\n", n1, n2, AddIntegers(n1, n2));
  48.  
  49.     /* Add two real numbers. */
  50.     printf("%f + %f = %f\n", f1, f2, AddReals(f1, f2));
  51.  
  52.     return (0);
  53. }
  54.