Docsity

Practice Assignment 7 - Programming Using C | CGS 3460, Assignments of Computer Science

Toggle sidebar
bg1
CGS 3460 - Programming Using C
Fall 2008
Assignment #7
Assigned: Tuesday, October 7th, 2008
Due: Monday, October 13th, 2008 at 11:59 PM
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);
pf3
pf4

Partial preview of the text

Download Practice Assignment 7 - Programming Using C | CGS 3460 and more Assignments Computer Science in PDF only on Docsity!

CGS 3460 - Programming Using C

Fall 2008

Assignment

Assigned: Tuesday, October 7th, 2008

Due: Monday, October 13

th

, 2008 at 11:59 PM

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.

  1. Then transfer p1.c, p2.c to assign7 directory on rain using WinSCP.
  2. Go to step 1 to tar the file using putty.
  3. Use WinSCP to copy assign7.tar from rain machine back to your local computer, say desktop.
  4. Upload the assign7.tar to WebCT.
  5. Please check the discussion page for assignment 7 on WebCT for common questions and their answers