| | |
is this matrix code working?
![]() |
•
•
Join Date: Nov 2006
Posts: 6
Reputation:
Solved Threads: 0
Is this code compiling
#include <iostream> usingnamespace std; //Define the Matrix3X3 type. typedefstruct { float index[3][3]; } Matrix3X3; //Function prototypes (functions are defined below main()) void printMatrix( Matrix3X3 a ); Matrix3X3 inputMatrix(); Matrix3X3 addMatrices( Matrix3X3 a, Matrix3X3 b ); Matrix3X3 subtractMatrices( Matrix3X3 a, Matrix3X3 b ); Matrix3X3 scalarMultiply( Matrix3X3 a, float scale ); //main() function void main() { cout << "Please enter matrix A:" << endl; Matrix3X3 A = inputMatrix(); cout << "Matrix A:" << endl; printMatrix( A ); cout << "Please enter matrix B:" << endl; Matrix3X3 B = inputMatrix () ; cout << "Matrix B:" <<endl; printMatrix ( B ); printMatrix(scalarMultiply(A, 3.1415)); } Matrix3X3 scalarMultiply( Matrix3X3 a, float scale ) { Matrix3X3 result; for(int i=0;i<3; i++) for(int j=0;j<3; j++) result.index[j][i] = scale * a.index[j][i]; return result; } Matrix3X3 subtractMatrices( Matrix3X3 a, Matrix3X3 b ) { Matrix3X3 result; for(int i=0;i<3; i++) for(int j=0;j<3; j++) result.index[j][i] =a.index[j][i] - b.index[j][i]; return result; } void printMatrix( Matrix3X3 a ) { //loop through rows for( int i=0; i < 3; ++i ) { //loop through column at each row for( int j=0; j < 3; ++j ) { //i is the row //j is the column float temp = a.index[i][j]; cout << temp << " "; } //go to the next line after each row cout << endl; } } Matrix3X3 inputMatrix() { Matrix3X3 temp; //loop through rows for( int i=0; i < 3; ++i ) { //loop through column at each row for( int j=0; j < 3; ++j ) { //i is the row //j is the column cout << "Enter row " << i << " column " << j << ":" << endl; cin >> temp.index[i][j]; } } return temp; }
![]() |
Similar Threads
- Problem with Gauss Matrix Code (C++)
- I would liike to multiply two matrices but my code is not working..help me out! (C++)
- event code not working (Java)
- Need help with DirectX code (C)
Other Threads in the C++ Forum
- Previous Thread: Looking for help with C++ game of life program. Will pay or make donation for tutor.
- Next Thread: Assistace please
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ char class classes classified code coding compatible compile console conversion count date delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file filewrite forms fstream function functions game givemetehcodez graph gui homeworkhelp homeworkhelper homeworksolutions iamthwee icon if...else ifstream input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node object output play pointer problem program programming project python random read recursion reference rpg string strings struct symbol temperature template test text text-file toolkit tree url values variable vector video win32 windows winsock wordfrequency wxwidgets






