Quiz 7 and Solutions

Implementaprogramtorealizematrixoperationdabcgivenaisa

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: }; d) for(int i = 0; i < 2; i++) for(int j = 0; j < 2; j++) x[i * 2 + j] = j; // This doesn’t work e) x[2][2] = {{2, 1}}; 3. Implement a program to realize matrix operation D = A * B + C, given A is a m x n matrix, B a n x m matrix. C and D are both m x m matrixes. Suppose A, B and C has already been initialized with initial value. Solutions 1. a) when n = 2; b) when n = 3; c) when n = 1; d) when n = 5; 2. a, b, c, e 3. int main() { int A[m][n]; int B[n][m]; int C[m][m]; for(int i = 0; i < m; i++) for(int j = 0; j < m; j++) { D[i][j] = 0; for(int k = 0; k < n; k++) D[i][j] += A[i][k] * B[k][j]; D[i][j] +=C[i][j]; } Return 0; }...
View Full Document

This note was uploaded on 10/23/2011 for the course ECE 224 taught by Professor Wangxin during the Spring '09 term at SUNY Stony Brook.

Ask a homework question - tutors are online