lec10-cs110 computational engineering

Download Lec10-CS110 Computational Engineering

Post on 22-May-2015




0 download

Embed Size (px)


A keynote on Problem Solving using Computers


  • 1. CS110: Matrix operations in C Lecture 10 V. Kamakoti 29th January 2008

2. Arrays Matrix is A two dimensional array Array of one dimensional arrays Stored in memory Row-wise (Row Major order) Column-wise (Column Major order) 3. Storage of matrix A - 2X3 matrix has elements A[0][0],A[0][1],A[0][2]; A[1][0],A[1][1],A[1][2]; A[2][0],A[2][1],A[2][2]; Assume it is an integer matrix and A[0][0] is stored at 1000 4. Row-major order Store the first row, then, the second, then, the third and so on A - 2X3 matrix has elements A[0][0],A[0][1],A[0][2]; stored at 1000-1011 A[1][0],A[1][1],A[1][2]; stored 1012 - 1023 A[2][0],A[2][1],A[2][2]; stored 1024 - 1035 5. Column-major order Store the first column, then, the second column, then, the third and so on.. A - 2X3 matrix has elements A[0][0],A[1][0],A[2][0]; stored at 1000-1011 A[0][1],A[1][1],A[2][1]; stored 1012 - 1023 A[0][2],A[1][2],A[2][2]; stored 1024 - 1035 The C compiler assumes Row major order. 6. Lab - 3 Write a program that reads in the entries of a 3 by 3 matrix, and prints it out in the form of a matrix. The entries could be floating point entries too. 7. Solution #include main() { int i,j, a[3][3]; for (i = 0; i