Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <Windows.h>
- #include <tchar.h>
- typedef size_t index_t;
- #define DEC 10
- enum position {
- TOP,
- CENTER,
- BOTTOM,
- HORIZONTAL = 196,
- TOP_LEFT = 218,
- TOP_CENTER = 194,
- TOP_RIGHT = 191,
- CENTER_LEFT = 195,
- CENTER_CENTER = 197,
- CENTER_RIGHT = 180,
- BOTTOM_LEFT = 192,
- BOTTOM_CENTER = 193,
- BOTTOM_RIGHT = 217,
- VERTICAL = 179
- };
- void table(enum position, unsigned);
- int main() {
- index_t _col, _row, _multiplication;
- const unsigned _size = 10;
- SetConsoleTitleW(_T("Таблица умножения"));
- system("color 9B");
- table(TOP, _size);
- for (_row = 0; _row < _size; _row++) {
- for (_col = 0; _col < _size; _col++) {
- if (!_row && !_col) printf("%c ", VERTICAL);
- else if (!_row) printf("%c %i", VERTICAL, _col);
- else if (!_col) printf("%c %i", VERTICAL, _row);
- else {
- _multiplication = _col * _row;
- if (_multiplication < DEC) printf("%c %i", VERTICAL, _multiplication);
- else printf("%c%i", VERTICAL, _multiplication);
- }
- }
- printf("%c\n", VERTICAL);
- if (_row < _size - 1) table(CENTER, _size);
- }
- table(BOTTOM, _size);
- getchar();
- return 0;
- }
- void table(enum position __line, unsigned __cols) {
- unsigned char _left, _center, _right, _current;
- size_t _width = __cols * 3 + 1;
- index_t _n;
- switch (__line) {
- case TOP:
- _left = TOP_LEFT;
- _center = TOP_CENTER;
- _right = TOP_RIGHT;
- break;
- case CENTER:
- _left = CENTER_LEFT;
- _center = CENTER_CENTER;
- _right = CENTER_RIGHT;
- break;
- case BOTTOM:
- _left = BOTTOM_LEFT;
- _center = BOTTOM_CENTER;
- _right = BOTTOM_RIGHT;
- break;
- default: printf("Error: __line argument does not exist\n\a");
- }
- for (_n = 0; _n < _width; _n++) {
- if (!_n) _current = _left;
- else if (_n == _width - 1) _current = _right;
- else if (!(_n % 3)) _current = _center;
- else _current = HORIZONTAL;
- printf("%c", _current);
- }
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement