[Cpp-Programming] Re: help
Reep,
both programs are good except few statements..
First Program:
Here you defined row and column = 4 but your loop a<row-1 i.e. a<3 will execute only three times. I believe u are trying to add 4x4 matrix, so just change all the for loops condition to either a <= row-1 or a < row. If u want 3x3 matrix, then define row and column as 3 and make changes in all for loops as suggested above.
Second thing, remove the defination of c d e f g h, it is unneccassarily occupying the memory.
Second program:
Looks good but i am not sure about cin>>c>>d; will it ask for value once and assign it to both the variables i.e. c and d? I mostly worked on C, so never used cin/cout, sorry.
Let me know if u have any question.
~Atul
On Thu, Mar 12, 2009 at 8:56 PM, reepakmajhi.com@gmail.com <reepakmajhi.com@gmail.com> wrote:
is this 2 program code right of two matrix addition
1st program
#include<iostream.h>
#define row 4
#define col 4
int main()
{
int i[row][col],j[row][col],k[row][col];
int a,b,c,d,e,f,g,h;
for(a=0;a<row-1;a++)
{ cout<<"\n";
for(b=0;b<col-1;b++)
cin>>i[a][b];
}
for(a=0;a<row-1;a++)
{ cout<<"\n";
for(b=0;b<col-1;b++)
cin>>j[a][b];
}
for(a=0;a<row-1;a++)
{ cout<<"\n";
for(b=0;b<col-1;b++)
k[a][b]= j[a][b]+i[a][b]; }
for(a=0;a<row-1;a++)
{cout<<"\n";
for(b=0;b<col-1;b++)
cout<<"\t";
cout<<k[a][b];}
system("pause"); }
2nd program
#include<iostream.h>
int main()
{
int i[10][10],j[10][10],k[10][10];
int a,b,c,d,e,f;
cin>>c>>d;
cin>>e>>f;
for(a=0;a<c;a++)
{ cout<<"\n";
for(b=0;b<d;b++)
cin>>i[a][b];
}
for(a=0;a<e;a++)
{ cout<<"\n";
for(b=0;b<f;b++)
cin>>j[a][b];
}
for(a=0;a<c;a++)
{ cout<<"\n";
for(b=0;b<d;b++)
k[a][b]= j[a][b]+i[a][b]; }
for(a=0;a<c;a++)
{cout<<"\n";
for(b=0;b<d;b++)
cout<<"\t";
cout<<k[a][b];}
system("pause"); }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "C++ Programming" group.
To post to this group, send email to Cpp-Programming@googlegroups.com
To unsubscribe from this group, send email to Cpp-Programming+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/Cpp-Programming?hl=en
-~----------~----~----~----~------~----~------~--~---
0 Comments:
Post a Comment
<< Home