[Solved] CSCI2500 Homework 1-Matrix multiplication

$25

File Name: CSCI2500_Homework_1-Matrix_multiplication.zip
File Size: 386.22 KB

SKU: [Solved] CSCI2500 Homework 1-Matrix multiplication Category: Tag:
5/5 - (1 vote)

In this first individual homework assignment, you will implement matrix multiplication. (For you Math dual majors, youre welcome.) If you need a refresher in how matrix multiplication works, look in a math textbook or check out Wikipedia. Note that we will revisit this topic in the future, but for now you will implement your algorithm in C.

Command-Line Arguments

Four command-line arguments are required (i.e., argv[1] through argv[4]). The first two commandline arguments specify how many rows and columns are in the first matrix, and the second two command-line arguments specify how many rows and columns are in the second matrix. To properly translate the command-line arguments, use the atoi() function, which you can learn more about by checking out the man page.

Once the pair of matrix dimensions are identified and validated, prompt the user to enter the values (non-negative integers) of each matrix. Use scanf() to read in the appropriate values.

Example Program Execution

On the next page are example program executions that you can use to better understand how your program should work and how you can begin to test your code. Note that your program must properly return either EXIT_SUCCESS or EXIT_FAILURE, which you can verify via echo$?.

Also, be sure to match the output formatting exactly as shown (to ensure full credit on Submitty). In particular, when displaying a matrix, each line must start with [ and end with ] (as shown below). Further, right justify and vertically line up your columns as follows:

[12 34 5567]

[ 8 9 123]

[45 67 8]

[ 9 10 11]

Example program executions are shown below:

bash$ ./a.out 2 3 3 1

Please enter the values for the first matrix (23):

1 2 3

4 5 6

Please enter the values for the second matrix (31):

7

8

9

[1 2 3]

[4 5 6]

multiplied by

[7]

[8] [9] equals

[ 50]

[122] bash$ echo $?

0

bash$ ./a.out 4 5 6 7 ERROR: Invalid inputs! bash$ echo $?

1

bash$ ./a.out 2 2 2 2

Please enter the values for the first matrix (22):

1 2

3 4

Please enter the values for the second matrix (22):

5 6

7 8

[1 2] [3 4] multiplied by [5 6]

[7 8]

equals [19 22] [43 50] bash$ echo $? 0

2

Starting Point

Below is a starting point for your code (e.g., hw1.c):

/* hw1.c */

/* NAME: <your-name-here> */

#include <stdio.h>

#include <stdlib.h> #include <math.h>

int main( int argc, char * argv[] )

{

/* Ensure we have the correct number of command-line arguments */ if ( argc != 5 )

{ fprintf( stderr, ERROR: Invalid inputs!
); return EXIT_FAILURE;

}

return EXIT_SUCCESS;

}

Note that if an error occurs, use either perror() or fprintf( stderr, ), depending on whether the global errno is set.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CSCI2500 Homework 1-Matrix multiplication
$25