Advertisement
NickAndNick

Таблица умножения

Jul 14th, 2013
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.32 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <Windows.h>
  3. #include <tchar.h>
  4. typedef size_t index_t;
  5. #define DEC 10
  6. enum position {
  7.     TOP,
  8.     CENTER,
  9.     BOTTOM,
  10.     HORIZONTAL      = 196,
  11.     TOP_LEFT        = 218,
  12.     TOP_CENTER      = 194,
  13.     TOP_RIGHT       = 191,
  14.     CENTER_LEFT     = 195,
  15.     CENTER_CENTER   = 197,
  16.     CENTER_RIGHT    = 180,
  17.     BOTTOM_LEFT     = 192,
  18.     BOTTOM_CENTER   = 193,
  19.     BOTTOM_RIGHT    = 217,
  20.     VERTICAL        = 179
  21. };
  22. void table(enum position, unsigned);
  23. int main() {
  24.     index_t _col, _row, _multiplication;
  25.     const unsigned _size = 10;
  26.     SetConsoleTitleW(_T("Таблица умножения"));
  27.     system("color 9B");
  28.     table(TOP, _size);
  29.     for (_row = 0; _row < _size; _row++) {
  30.         for (_col = 0; _col < _size; _col++) {
  31.             if (!_row && !_col) printf("%c  ", VERTICAL);
  32.             else if (!_row) printf("%c %i", VERTICAL, _col);
  33.             else if (!_col) printf("%c %i", VERTICAL, _row);
  34.             else {
  35.                 _multiplication = _col * _row;
  36.                 if (_multiplication < DEC) printf("%c %i", VERTICAL, _multiplication);
  37.                 else printf("%c%i", VERTICAL, _multiplication);
  38.             }
  39.         }
  40.         printf("%c\n", VERTICAL);
  41.         if (_row < _size - 1) table(CENTER, _size);
  42.     }
  43.     table(BOTTOM, _size);
  44.     getchar();
  45.     return 0;
  46. }
  47. void table(enum position __line, unsigned __cols) {
  48.     unsigned char _left, _center, _right, _current;
  49.     size_t _width = __cols * 3 + 1;
  50.     index_t _n;
  51.     switch (__line) {
  52.         case TOP:
  53.             _left   = TOP_LEFT;
  54.             _center = TOP_CENTER;
  55.             _right  = TOP_RIGHT;
  56.             break;
  57.         case CENTER:
  58.             _left   = CENTER_LEFT;
  59.             _center = CENTER_CENTER;
  60.             _right  = CENTER_RIGHT;
  61.             break;
  62.         case BOTTOM:
  63.             _left   = BOTTOM_LEFT;
  64.             _center = BOTTOM_CENTER;
  65.             _right  = BOTTOM_RIGHT;
  66.             break;
  67.         default: printf("Error: __line argument does not exist\n\a");
  68.     }
  69.     for (_n = 0; _n < _width; _n++) {
  70.         if (!_n) _current = _left;
  71.         else if (_n == _width - 1) _current = _right;
  72.         else if (!(_n % 3)) _current = _center;
  73.         else _current = HORIZONTAL;
  74.         printf("%c", _current);
  75.     }
  76.     printf("\n");
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement