| | |
is this matrix code working?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
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 beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






