Table of Contents

Corning Community College

ENGR1050 C for Engineers

Project: LOOPS - MATH TABLE FUN (mtf1)

Objective

To continue incorporating loops into our problem-solving repertoire, aiding us in displaying information related to various math tables.

Reading

In “The C Book”, please read through Chapter 5.

Program

It is your task to enhance the program you wrote last week (mtf0) that will use loops and other programming concepts learned this far to automate the display of entire mathematical operation tables (addition, subtraction, multiplication, division, or remainder; as indicated by the user). This information is potentially of value to some of your letter division efforts in the pctX projects.

Specifications

Your program should:

Some additional points of consideration:

Compiling

As we have been doing all along, use the following options to gcc when compiling:

lab46:~/src/c4eng/mtf1$ gcc -Wall --std=gnu99 -o mtf1 mtf1.c
lab46:~/src/c4eng/mtf1$ 

Execution

Sample run using multiplication

lab46:~/src/c4eng/mtf1$ ./mtf1
Which operation: *
Starting Row (0-9): 4
Ending Row (0-9): 8
Starting Column (0-9): 1
Ending Column (0-9): 5
 * |  1  2  3  4  5
---+----------------
 4 |  4  8 12 16 20
 5 |  5 10 15 20 25
 6 |  6 12 18 24 30
 7 |  7 14 21 28 35
 8 |  8 16 24 32 40
lab46:~/src/c4eng/mtf1$ 

The execution of the program is short and simple- obtain the input, do the processing, produce the output, and then terminate.

Sample run using addition

lab46:~/src/c4eng/mtf1$ ./mtf1
Which operation: +
Starting Row (0-9): 5
Ending Row (0-9): 7
Starting Column (0-9): 2
Ending Column (0-9): 7
 + |  2  3  4  5  6  7
---+-------------------
 5 |  7  8  9 10 11 12
 6 |  8  9 10 11 12 13
 7 |  9 10 11 12 13 14
lab46:~/src/c4eng/mtf1$ 

Sample run using subtraction

lab46:~/src/c4eng/mtf1$ ./mtf1
Which operation: -
Starting Row (0-9): 2
Ending Row (0-9): 6
Starting Column (0-9): 1
Ending Column (0-9): 4
 - |  1  2  3  4
---+-------------
 2 |  1  0 -1 -2
 3 |  2  1  0 -1
 4 |  3  2  1  0
 5 |  4  3  2  1
 6 |  5  4  3  2
lab46:~/src/c4eng/mtf1$ 

Sample run using division

lab46:~/src/c4eng/mtf1$ ./mtf1
Which operation: /
Starting Row (0-9): 6
Ending Row (0-9): 9
Starting Column (0-9): 0
Ending Column (0-9): 4
 / |  0  1  2  3  4
---+----------------
 6 | NA  6  3  2  1
 7 | NA  7  3  2  1
 8 | NA  8  4  2  2
 9 | NA  9  4  3  2
lab46:~/src/c4eng/mtf1$ 

Sample run using remainder

lab46:~/src/c4eng/mtf1$ ./mtf1
Which operation: %
Starting Row (0-9): 5
Ending Row (0-9): 8
Starting Column (0-9): 1
Ending Column (0-9): 5
 % |  1  2  3  4  5
---+----------------
 5 |  0  1  2  1  0
 6 |  0  0  0  2  1
 7 |  0  1  1  3  2
 8 |  0  0  2  0  3
lab46:~/src/c4eng/mtf1$ 

Sample run with invalid operation given

lab46:~/src/c4eng/mtf1$ ./mtf1
Which operation: x
ERROR: Must specify '+', '-', '*', '/', or '%'.
lab46:~/src/c4eng/mtf1$ 

Sample run with invalid row configuration

lab46:~/src/c4eng/mtf1$ ./mtf1
Which operation: +
Starting Row (0-9): 7
Ending Row (0-9): 2
ERROR: Starting row is greater than ending row
lab46:~/src/c4eng/mtf1$ 

Reference

In the C4ENG public directory, inside the mtf1 subdirectory, will be a copy of my implementation (in executable form), which abides by the project specifications. Please compare its output against that of your implementation.

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 c4eng mtf1 mtf1.c
Submitting c4eng 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.

What I'll be looking for:

78:mtf1:final tally of results (78/78)
*:mtf1:proper error checking and status reporting performed [13/13]
*:mtf1:correct variable types and name lengths used [13/13]
*:mtf1:proper output formatting per specifications [13/13]
*:mtf1:runtime tests of submitted program succeed [13/13]
*:mtf1:no negative compiler messages for program [13/13]
*:mtf1:code is pushed to lab46 repository [13/13]

Additionally: