Prgramming Assignment

A kind of sparse matrix is banded matrix. If square matrix A is of size n´n, a lower band element of bandwidth r is the element ai,j such that 0<i-j£r and an upper band element of bandwidth s is the element ai,j such that 0<j-i£s. Only the elements on the diagonal, on the lower band, and on the upper band can be non-zero; all other elements are called off-band elements and they are all zeros. The following is an example of an 8´8 banded matrix with the lower bandwidth r of 2 and the upper bandwidth s of 3:

Let the size of square matrix A, B, and C be n´n. Also, let ra and sa be the lower and upper bandwidth of sqaure matrix A, respectively, and rb and sb be the lower and upper bandwidth of sqaure matrix B, respectively. If C=A´B, then the lower bandwidth of C is ra+rb and the upper bnadwdth of C is sa+sb with the limit of upper bound n-1. The non-zero elements of ci,j is computed as the following formula:

Write a C program to input an integer n of square matrix size for matrice A, B, and C, and two pairs of integer, ra and sa as the lower and upper bandwidth of matrix A, and rb and sb as the lower and upper bandwidth of matrix B. Use dynamic memory allocation to create exact space for banded matrices A, B, and C and randomly generate non-zero ai,j and bi,j for matrices A and B. Then, compute matrix multiplication C=A´B. Output matrices A, B, and C; do not output the off-band elements form matrices A, B, and C.

Program execution example: