| | |
matrix addition
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2008
Posts: 5
Reputation:
Solved Threads: 0
Hi all,
I have tried to write a program which can add two matrix.
It is running well....but when I am printing out the resultant matrix it is just showing the address of the resultant elements.
For convenience, I have posted the output also.
Program:-
O/p:
1st Matrix:
1 1 1
1 1 1
1 1 1
2nd Matrix:
1 1 1
1 1 1
1 1 1
Resultant:
0xbfe1b810 0xbfe1b81c 0xbfe1b828
0xbfe1b810 0xbfe1b81c 0xbfe1b828
0xbfe1b810 0xbfe1b81c 0xbfe1b828
I have tried to write a program which can add two matrix.
It is running well....but when I am printing out the resultant matrix it is just showing the address of the resultant elements.
For convenience, I have posted the output also.
Program:-
C++ Syntax (Toggle Plain Text)
#include<iostream.h> int main() { int mat1[3][3]; int mat2[3][3]; int i,j; cout<<"\n1st Matrix: \n"<<flush; for(i=0;i<3;i++) { for(j=0;j<3;j++) { cin>>mat1[i][j]; } } cout<<"\n2nd Matrix: \n"<<flush; for(i=0;i<3;i++) { for(j=0;j<3;j++) { cin>>mat2[i][j]; } } int mat[3][3]; int k,l; cout<<"\nResultant: \n"<<flush; for(k=0;k<3;k++) { for(l=0;l<3;l++) { mat[k][l]=(mat1[k][l]+mat2[k][l]); cout<<" "<<mat[l]<<flush; } cout<<"\n"<<flush; } return 0; }
1st Matrix:
1 1 1
1 1 1
1 1 1
2nd Matrix:
1 1 1
1 1 1
1 1 1
Resultant:
0xbfe1b810 0xbfe1b81c 0xbfe1b828
0xbfe1b810 0xbfe1b81c 0xbfe1b828
0xbfe1b810 0xbfe1b81c 0xbfe1b828
Last edited by Ancient Dragon; Jan 2nd, 2009 at 10:09 am. Reason: add code tags
Why are you flushing so much? The problem is that you can't directly print an array. You have to print from both indices, so Also, iostream.h isn't standard. <iostream> is. Which compiler are you using?
C++ Syntax (Toggle Plain Text)
for(k=0;k<3;k++) { for(l=0;l<3;l++) { mat[k][l]=(mat1[k][l]+mat2[k][l]); cout<<" "<<(mat[k][l]); } cout<<"\n"; }
![]() |
Similar Threads
- Method that recieves matrix values as a string (C#)
- Addition with Two Dimensional Arrays (C++)
- need help (C)
- How to pass reference of a 2-D matrix to a function in C (C)
- adding matrices in c++ (C++)
- Need help Enlarging a Matrix (C)
Other Threads in the C++ Forum
- Previous Thread: C++ Harddisk Size/Usage
- Next Thread: Library to solve matrix determinant c++
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion count data database delete desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project proxy python random read recursion recursive return sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






