


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Assigned: Tuesday, October 7th, 2008
th
Please Note: Any compilation error will be subjected to at least 50% penalty of the total assignment grade.
1. Write a C program that reads in two matrices of float values and calculates their product. The matrices have a maximum size of 100 columns and 100 rows. The functions will take 100x100 arrays as parameters and perform desired tasks on the specified portions of those arrays.
The first function will read a matrix from the input. It will have the following parameters; a two-dimension float array (this array will be of size 100x100), the number of rows to read, the number of columns to read, and a character representing the name of the matrix. Your function will fill the portion of the array that's specified by number of rows and number of columns.
The second function will receive the following parameters: a two-dimensional array of float values, the number of rows, and the number of columns. This function will print the matrix in a table format, i.e. adjusting the spaces so that columns are aligned vertically.
Your program should first read the matrix dimensions from the user, and check them. The multiplication of two matrices requires the column count of the first matrix to be equal to the row count of the second one; so that columns are always aligned.
In case you are not familiar with matrix multiplication you can read this: http://en.wikipedia.org/wiki/Matrix_multiplication. Save this program as p1.c. A sample session with your program is displayed below.
Hint:
// You can define the array like this float matrixA[100][[100];
// Your function definition for read matrix will look like this void readMatrix(float matrix[][100], int rowCount, int columnCount, char matrixName);
// Your function definition for print matrix will look like this void printMatrix(float matrix[][100], int rowCount, int columnCount);
Example 1:
Enter row count for A 2 Enter column count for A 3
Enter A[1][1] 1 Enter A[1][2] 0 Enter A[1][3] 2 Enter A[2][1]
Enter A[2][2] 3 Enter A[2][3] 1
Enter row count for B 3 Enter column count for B 2
Enter B[1][1] 3 Enter B[1][2] 1 Enter B[2][1] 2 Enter B[2][2] 1 Enter B[3][1] 1 Enter B[3][2] 0
AB is [2][2]:
5.000000 1. 4.000000 2.