home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / qc_prog / chap05 / m.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-05  |  1.4 KB  |  52 lines

  1. /* m.c -- draw a letter M        */
  2. /*        using IF and CONTINUE  */
  3.  
  4. /* define characters */
  5.  
  6. #define CH 'M'    /* character to "draw" with */
  7. #define BLANK ' '
  8. #define NL 10
  9. #define CR 13
  10. #define LEFT 20   /* left side of M   */
  11. #define RIGHT 46  /* right side of M  */
  12. #define BOTTOM 22 /* last line to use */
  13. main()
  14. {
  15.     int pos, line;
  16.     /* space to left side */
  17.     for (line = 1; line <= BOTTOM; line++)
  18.         {
  19.         for (pos = 1; pos < LEFT; pos++)
  20.             {
  21.             putch(BLANK);
  22.             }
  23.         putch(CH); /* draw left side */
  24.  
  25.         /* are we past midpoint? */
  26.         if (line > ((RIGHT - LEFT) / 2))
  27.             {
  28.             /* yes, so just draw right side */
  29.             for (pos = LEFT; pos < RIGHT; pos++)
  30.                 {
  31.                 putch(BLANK);
  32.                 }
  33.             putch(CH);
  34.             putch(NL);
  35.             putch(CR);
  36.             continue; /* start loop over, do next line */
  37.             }
  38.             /* not past midpoint, check for interior */
  39.         for (pos = LEFT; pos < RIGHT; pos++)
  40.             {
  41.             if ((pos == (LEFT + line )) ||
  42.                  (pos == (RIGHT - line )))
  43.                 putch(CH);
  44.             else
  45.                 putch(BLANK);
  46.             }
  47.        putch(CH);
  48.        putch(NL);
  49.        putch(CR); /* could also use printf("\n"); */
  50.        }
  51. }
  52.