Proj#1 - } } m=row; if (num!=m*n) //error when the input...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <stdio.h> #include <stdlib.h> int main( void ) { //m,n are numbers of row and columns in input matrix. row and col are indexs for row and column. //num are number of entries in input matrix. int matrix[10][10],trans[10][10],product[10][10]={0},m,n,row=0,col=0,num=0,k=0; char c= 'c' ; printf( "Enter the number of columns in matrix A: " ); if (scanf( "%d" //error when the value enter is not a number,such as a letter. { printf( "\nERROR:The number of colums should be a numerical value.\n\n" ); exit(1); } else if (n>10 || n<=0) //error when number of columns is not in available range. { printf( "\nERROR:The number of colums should not be negative or 0 or greater than 10.\n\n" ); exit(1); } printf( "\nEnter the elements in A:\n" ); for (row=0;c!= '\n' ;row++) { if (row>=10) //error when there are more than 10 rows in input matrix { printf( "ERROR:Too many rows in this matrix, maximum number of row is 10.\n\n" ); exit(1); } for '\n' ;col++) { if (scanf( "%d" num++; c=getchar(); //scan for '\n' in buffer, stop scanning for more input when '\n' is found
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } } m=row; if (num!=m*n) //error when the input matrix is imcomplete { printf( &quot;ERROR: This is not a complete matrix.&quot; ); exit(1); } //transpose matrix for (row=0;row&lt;m;row++) for (col=0;col&lt;n;col++) trans[col][row]=matrix[row][col]; //product matrix for (row=0;row&lt;m;row++) for (col=0;col&lt;m;col++) for (k=0;k&lt;n;k++) product[row][col]+=matrix[row][k]*trans[k][col]; //print input matrix printf( &quot;\nMatrix A is:\n&quot; ); for (row=0;row&lt;m;row++) { for (col=0;col&lt;n;col++) printf( &quot;%3d &quot; ,matrix[row][col]); printf( &quot;\n&quot; ); } //print transpose matrix printf( &quot;\nTranspose matrix A^T is:\n&quot; ); for (row=0;row&lt;n;row++) { for (col=0;col&lt;m;col++) printf( &quot;%3d &quot; ,trans[row][col]); printf( &quot;\n&quot; ); } //print product matrix printf( &quot;\nProduct matrix A*A^T is:\n&quot; ); for (row=0;row&lt;m;row++) { for (col=0;col&lt;m;col++) printf( &quot;%3d &quot; ,product[row][col]); printf( &quot;\n&quot; ); } return 0; }...
View Full Document

This note was uploaded on 09/05/2011 for the course EE 150 taught by Professor Lanxiang during the Spring '11 term at Montgomery College.

Page1 / 2

Proj#1 - } } m=row; if (num!=m*n) //error when the input...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online