Table of Contents

Corning Community College

CSCS2330 Discrete Structures

Project: MATH TABLE FUN - MULTIBASE (mtf1)

Errata

Any changes that have been made.

Objective

To continue exploring your number base/number representation skills in implementing an multibase addition, subtraction, multiplication, division, or remainder table generating program.

Program

Write a program that generates a table:

Program Output

Default, no options or settings alterations

lab46:~/src/discrete/mtf1$ ./mtf1
      1  2  3  4  5  6  7  8  9 
  [*]--------------------------- 
 1 |  1  2  3  4  5  6  7  8  9
 2 |  2  4  6  8 10 12 14 16 18
 3 |  3  6  9 12 15 18 21 24 27
 4 |  4  8 12 16 20 24 28 32 36
 5 |  5 10 15 20 25 30 35 40 45
 6 |  6 12 18 24 30 36 42 48 54
 7 |  7 14 21 28 35 42 49 56 63
 8 |  8 16 24 32 40 48 56 64 72
 9 |  9 18 27 36 45 54 63 72 81

Altering the operation to perform (addition)

lab46:~/src/discrete/mtf1$ MTF1_OPER="+" ./mtf1
      1  2  3  4  5  6  7  8  9 
  [+]--------------------------- 
 1 |  2  3  4  5  6  7  8  9 10
 2 |  3  4  5  6  7  8  9 10 11
 3 |  4  5  6  7  8  9 10 11 12
 4 |  5  6  7  8  9 10 11 12 13
 5 |  6  7  8  9 10 11 12 13 14
 6 |  7  8  9 10 11 12 13 14 15
 7 |  8  9 10 11 12 13 14 15 16
 8 |  9 10 11 12 13 14 15 16 17
 9 | 10 11 12 13 14 15 16 17 18

Subtraction

lab46:~/src/discrete/mtf1$ MTF1_OPER="-" ./mtf1 7
      1  2  3  4  5  6 
  [-]------------------ 
 1 |  0 -1 -2 -3 -4 -5
 2 |  1  0 -1 -2 -3 -4
 3 |  2  1  0 -1 -2 -3
 4 |  3  2  1  0 -1 -2
 5 |  4  3  2  1  0 -1
 6 |  5  4  3  2  1  0

Division

lab46:~/src/discrete/mtf1$ MTF1_OPER="/" ./mtf1 16
      1  2  3  4  5  6  7  8  9  A  B  C  D  E  F 
  [/]--------------------------------------------- 
 1 |  1  0  0  0  0  0  0  0  0  0  0  0  0  0  0
 2 |  2  1  0  0  0  0  0  0  0  0  0  0  0  0  0
 3 |  3  1  1  0  0  0  0  0  0  0  0  0  0  0  0
 4 |  4  2  1  1  0  0  0  0  0  0  0  0  0  0  0
 5 |  5  2  1  1  1  0  0  0  0  0  0  0  0  0  0
 6 |  6  3  2  1  1  1  0  0  0  0  0  0  0  0  0
 7 |  7  3  2  1  1  1  1  0  0  0  0  0  0  0  0
 8 |  8  4  2  2  1  1  1  1  0  0  0  0  0  0  0
 9 |  9  4  3  2  1  1  1  1  1  0  0  0  0  0  0
 A |  A  5  3  2  2  1  1  1  1  1  0  0  0  0  0
 B |  B  5  3  2  2  1  1  1  1  1  1  0  0  0  0
 C |  C  6  4  3  2  2  1  1  1  1  1  1  0  0  0
 D |  D  6  4  3  2  2  1  1  1  1  1  1  1  0  0
 E |  E  7  4  3  2  2  2  1  1  1  1  1  1  1  0
 F |  F  7  5  3  3  2  2  1  1  1  1  1  1  1  1

Remainder

lab46:~/src/discrete/mtf1$ MTF1_OPER="%" ./mtf1 9
      1  2  3  4  5  6  7  8 
  [%]------------------------ 
 1 |  0  1  1  1  1  1  1  1
 2 |  0  0  2  2  2  2  2  2
 3 |  0  1  0  3  3  3  3  3
 4 |  0  0  1  0  4  4  4  4
 5 |  0  1  2  1  0  5  5  5
 6 |  0  0  0  2  1  0  6  6
 7 |  0  1  1  3  2  1  0  7
 8 |  0  0  2  0  3  2  1  0

Altering the base

lab46:~/src/discrete/mtf1$ ./mtf1 8
      1  2  3  4  5  6  7 
  [*]--------------------- 
 1 |  1  2  3  4  5  6  7
 2 |  2  4  6 10 12 14 16
 3 |  3  6 11 14 17 22 25
 4 |  4 10 14 20 24 30 34
 5 |  5 12 17 24 31 36 43
 6 |  6 14 22 30 36 44 52
 7 |  7 16 25 34 43 52 61

Altering the base, extending the upper bound

lab46:~/src/discrete/mtf1$ ./mtf1 12 13
        1   2   3   4   5   6   7   8   9   A   B  10  11 
   [*]---------------------------------------------------- 
  1 |   1   2   3   4   5   6   7   8   9   A   B  10  11
  2 |   2   4   6   8   A  10  12  14  16  18  1A  20  22
  3 |   3   6   9  10  13  16  19  20  23  26  29  30  33
  4 |   4   8  10  14  18  20  24  28  30  34  38  40  44
  5 |   5   A  13  18  21  26  2B  34  39  42  47  50  55
  6 |   6  10  16  20  26  30  36  40  46  50  56  60  66
  7 |   7  12  19  24  2B  36  41  48  53  5A  65  70  77
  8 |   8  14  20  28  34  40  48  54  60  68  74  80  88
  9 |   9  16  23  30  39  46  53  60  69  76  83  90  99
  A |   A  18  26  34  42  50  5A  68  76  84  92  A0  AA
  B |   B  1A  29  38  47  56  65  74  83  92  A1  B0  BB
 10 |  10  20  30  40  50  60  70  80  90  A0  B0 100 110
 11 |  11  22  33  44  55  66  77  88  99  AA  BB 110 121

All of that, plus lower bound

lab46:~/src/discrete/mtf1$ ./mtf1 13 8 2
      2  3  4  5  6  7  8 
  [*]--------------------- 
 2 |  4  6  8  A  C 11 13
 3 |  6  9  C 12 15 18 1B
 4 |  8  C 13 17 1B 22 26
 5 |  A 12 17 1C 24 29 31
 6 |  C 15 1B 24 2A 33 39
 7 | 11 18 22 29 33 3A 44
 8 | 13 1B 26 31 39 44 4C

Spacing, formatting, and presentation are centrally important. I want those headers and headings, and dividing lines. Your output should match my output (all to STDOUT).

An issue you might run into is how much space will you have to allocate (you want it universal for the display of the entire table). For that, I say determine the length of the maximum value being output (ie the bottom-most right value). That value’s length should then influence all the other output in the table.

Submission

To successfully complete this project, the following criteria must be met:

To submit this program to me using the submit tool, run the following command at your lab46 prompt:

$ submit discrete mtf1 mtf1.c
Submitting discrete project "mtf1":
    -> mtf1.c(OK)

SUCCESSFULLY SUBMITTED

You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches.