• [Integer Array] 2 * 2 Matrix Multiplier
    9 replies, posted
So here is a program I made to basically do matrices for me! Obviously it can be changed to 3 * 3, or anything really, even up to 100 * 100 if I want, but that would take longer, and I'm not going to need this, I just made it to practice arrays, which is the section of the book I'm learning from is at right now. What do you think? (Source code, compiled on MS VC++ 2010) [CODE] #include <iostream> using namespace std; int main() { int MatrixAns[2][2]; int a,b,c,d,w,x,y,z; int i,j; cout << "First matrix:\n"; cout << "Column 1, Row 1: "; cin >> a; cout << "Column 2, Row 1: "; cin >> b; cout << "Column 1, Row 2: "; cin >> c; cout << "Column 2, Row 2: "; cin >> d; cout << "\n\n"; cout << "Second matrix:\n"; cout << "Column 1, Row 1: "; cin >> w; cout << "Column 2, Row 1: "; cin >> x; cout << "Column 1, Row 2: "; cin >> y; cout << "Column 2, Row 2: "; cin >> z; system("CLS"); MatrixAns[0][0] = ( a * w ) + ( c * x ); MatrixAns[1][0] = ( b * w ) + ( d * x ); MatrixAns[0][1] = ( a * x ) + ( c * y ); MatrixAns[1][1] = ( b * x ) + ( d * y ); cout << "Answer:\n"; for(j=0;j<2;j++) { for(i=0;i<2;i++) { cout << "[" << MatrixAns[i][j] << "]"; cout << " "; } cout << "\n"; } cout << "\n"; system("PAUSE"); return 0; } [/CODE]
More algorithm less bullshit. But otherwise good, keep at it.
I'll give you an oatmeal cookie
Okay, I like using whitespace to make code more readable, but this is over the top.
[QUOTE=Dienes;34860365]Okay, I like using whitespace to make code more readable, but this is over the top.[/QUOTE] I think it is exactly what is needed.
I don't understand... explain how that huge amount of whitespace could possibly be needed? @OP - Good program, nice clean code, and good style (apart from the extreme whitespace).
Calm down guys, he was just using tabs which are displayed as 8 spaces in a [code] block Edit: Actually looks like this: [code]#include <iostream> using namespace std; int main() { int MatrixAns[2][2]; int a,b,c,d,w,x,y,z; int i,j; cout << "First matrix:\n"; cout << "Column 1, Row 1: "; cin >> a; cout << "Column 2, Row 1: "; cin >> b; cout << "Column 1, Row 2: "; cin >> c; cout << "Column 2, Row 2: "; cin >> d; cout << "\n\n"; cout << "Second matrix:\n"; cout << "Column 1, Row 1: "; cin >> w; cout << "Column 2, Row 1: "; cin >> x; cout << "Column 1, Row 2: "; cin >> y; cout << "Column 2, Row 2: "; cin >> z; system("CLS"); MatrixAns[0][0] = ( a * w ) + ( c * x ); MatrixAns[1][0] = ( b * w ) + ( d * x ); MatrixAns[0][1] = ( a * x ) + ( c * y ); MatrixAns[1][1] = ( b * x ) + ( d * y ); cout << "Answer:\n"; for(j=0;j<2;j++) { for(i=0;i<2;i++) { cout << "[" << MatrixAns[i][j] << "]"; cout << " "; } cout << "\n"; } cout << "\n"; system("PAUSE"); return 0; }[/code]
[QUOTE=Ziks;34878969]Calm down guys, he was just using tabs which are displayed as 8 spaces in a [code] block[/QUOTE] Yes, but why would you choose tabs over spaces after each and every token? Edit: And then again squeeze for-loop headers (which indeed have logical segments) into one bunch of characters...
I don't know, that is a bit odd
Yeah, the whitespace is much smaller on MSVC++10.
Sorry, you need to Log In to post a reply to this thread.