home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / ctutor2.zip / MACRO.C < prev    next >
Text File  |  1989-11-10  |  2KB  |  59 lines

  1.                                         /* Chapter 6 - Program 2 */
  2. #include "stdio.h"
  3.  
  4. #define WRONG(A) A*A*A          /* Wrong macro for cube     */
  5. #define CUBE(A) (A)*(A)*(A)     /* Right macro for cube     */
  6. #define SQUR(A) (A)*(A)         /* Right macro for square   */
  7. #define ADD_WRONG(A) (A)+(A)    /* Wrong macro for addition */
  8. #define ADD_RIGHT(A) ((A)+(A))  /* Right macro for addition */
  9. #define START 1
  10. #define STOP  7
  11.  
  12. void main()
  13. {
  14. int i,offset;
  15.  
  16.    offset = 5;
  17.    for (i = START;i <= STOP;i++) {
  18.       printf("The square of %3d is %4d, and its cube is %6d\n",
  19.               i+offset,SQUR(i+offset),CUBE(i+offset));
  20.       printf("The wrong of  %3d is %6d\n",i+offset,WRONG(i+offset));
  21.    }
  22.  
  23.    printf("\nNow try the addition macro's\n");
  24.    for (i = START;i <= STOP;i++) {
  25.       printf("Wrong addition macro = %6d, and right = %6d\n"
  26.                                ,5*ADD_WRONG(i),5*ADD_RIGHT(i));
  27.    }
  28. }
  29.  
  30.  
  31.  
  32. /* Result of execution
  33.  
  34. The square of   6 is   36, and its cube is    216
  35. The wrong of    6 is     16
  36. The square of   7 is   49, and its cube is    343
  37. The wrong of    7 is     27
  38. The square of   8 is   64, and its cube is    512
  39. The wrong of    8 is     38
  40. The square of   9 is   81, and its cube is    729
  41. The wrong of    9 is     49
  42. The square of  10 is  100, and its cube is   1000
  43. The wrong of   10 is     60
  44. The square of  11 is  121, and its cube is   1331
  45. The wrong of   11 is     71
  46. The square of  12 is  144, and its cube is   1728
  47. The wrong of   12 is     82
  48.  
  49. Now try the addition macro's
  50. Wrong addition macro =      6, and right =     10
  51. Wrong addition macro =     12, and right =     20
  52. Wrong addition macro =     18, and right =     30
  53. Wrong addition macro =     24, and right =     40
  54. Wrong addition macro =     30, and right =     50
  55. Wrong addition macro =     36, and right =     60
  56. Wrong addition macro =     42, and right =     70
  57.  
  58. */
  59.