Plz suggest me solution

I am trying to display a sequence of array in matrix form. But output is different from value assign to array.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
 #include <iostream>
#include<windows.h>
#include <cmath>
#include <string>

using namespace std;
int main()
{

float  x1, x2, x3, y1, y2, y3, y4; 
float  a1, a2, a3, b1, b2, b3, c1, c2, c3;
float area, l1, l2, l3, si1, si2, si3, fi1, fi2, fi3, fi4, fi5, fi6;

float d[6][6];

float m[6][6];

float k[6][6]= {{1,0,0,-1,0,-1},{0,1,0,-1,-1,0},{0,0,1,0,-1,-1},{0,0,0,0,0,0},{0,0,0,0,0,0},{0,0,0,0,0,0}}; 

float s[6][6]={{1,0,0,0,0,0},{0,1,0,0,0,0},{0,0,1,0,0,0},{-1,-1,0,0,0,0},{0,-1,-1,0,0,0},{-1,0,-1,0,0,0}};

cout<<" Transpose of Matrix [A]= "<<"\n\n";
for (int i=1; i<=6; ++i)
{
for(int j=1; j<=6; ++j)
{k[i][j]==0;
cout<<k[i][j]<<" "<<"\t";
}
cout<<"\n\n";
}
//******************************************************
 cout<<"\t\t Value of Mass Matrix :"<<"\n\n";
 
 for(int i=1; i<=6; i++)
{for(int j=1; j<=6; j++)
{d[i][j]=k[i][j]*s[j][i]+d[i][j];
cout<<"\t\t"<<d[i][j];
}cout<<"\n";}
cin>>c3;
return 0;

}
The index of an array starts with 0. This means that the range of indexes of an array with 6 elements goes from 0 to 5.

A loop looks like this:
for(int i=0; i<6; i++)
Hello @Ashutosh1234
1.-The index or subscript of an array begins 0,1,2,3,4,5..n not 1,2,3,4..n

I have an example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//printArray.cpp
//print an array

#include <iostream>
using std::cout;
using std::cin;
using std::endl;


int main(){

int myArray[3][3]={{1,2,3},{4,5,6},{7,8,9}};

cout<<"\nHello i have a two-dimensional array\n"
	<<"Array values:\n";
for(int i=0;i<3;i++){
	for(int j=0;j<3;j++){
		cout<<myArray[i][j]<<' ';
	}//end inner for
	cout<<endl;
}//end outer for

return 0; //indicates success
}//end main 



Eyenrique-MacBook-Pro:Study Eyenrique$ ./printArray 

Hello i have a two-dimensional array
Array values:
1 2 3 
4 5 6 
7 8 9 
Last edited on
thanks a lot for reply.

Will you please suggest code for matrix multiplication: I am getting different answer

#include <iostream>
#include<windows.h>
#include <cmath>
#include <string>

using namespace std;
int main()
{

float x1, x2, x3, y1, y2, y3, y4;
float a1, a2, a3, b1, b2, b3, c1, c2, c3;
float area, l1, l2, l3, si1, si2, si3, fi1, fi2, fi3, fi4, fi5, fi6;

float d[6][6];

float m[6][6];

float k[6][6]= {{1,0,0,-1,0,-1},{0,1,0,-1,-1,0},{0,0,1,0,-1,-1},{0,0,0,0,0,0},{0,0,0,0,0,0},{0,0,0,0,0,0}};

float s[6][6]={{1,0,0,0,0,0},{0,1,0,0,0,0},{0,0,1,0,0,0},{-1,-1,0,0,0,0},{0,-1,-1,0,0,0},{-1,0,-1,0,0,0}};

cout<<" Transpose of Matrix [A]= "<<"\n\n";
for (int i=0; i<=5; ++i)
{for(int j=0; j<=5; ++j)
{k[i][j]==0;
cout<<k[i][j]<<" "<<"\t";
}
cout<<"\n\n";}

//******************************************************
cout<<"\t\t Value of Mass Matrix :"<<"\n\n";

for(int i=0; i<=5; i++)
{for(int j=0; j<=5; j++)
{d[i][j]=k[i][j]*s[j][i]+d[i][j];
cout<<"\t\t"<<d[i][j];
}cout<<"\n";}
cin>>c3;
return 0;
}
There are 2 situations
if the matrices have same rows and columns and
if have different rows and columns

What program do you expect?
both? >.<
the second one have a little bit more problems!!!!
Hello Friends

I am trying to multiply two matrix but compiler shows error message in bold line. Please help me



#include <iostream>
#include<windows.h>
#include <cmath>
#include <string>
using std::cout;
using std::cin;
using std::endl;

using namespace std;
int main()
{

float x1, x2, x3, y1, y2, y3, y4;

float a1, a2, a3, b1, b2, b3, c1, c2, c3;

float area, l1, l2, l3, si1, si2, si3, fi1, fi2, fi3, fi4, fi5, fi6;

float d[6][6];

float m[6][6];

float k[6][6]= {{1,0,0,-1,0,-1},{0,1,0,-1,-1,0},{0,0,1,0,-1,-1},{0,0,0,0,0,0},{0,0,0,0,0,0},{0,0,0,0,0,0}};

float s[6][6]= {{1,0,0,0,0,0},{0,1,0,0,0,0},{0,0,1,0,0,0},{-1,-1,0,0,0,0},{0,-1,-1,0,0,0},{-1,0,-1,0,0,0}};


cout<<" Matrix [A]= "<<"\n\n";
for(int i=0; i<=5; ++i)
{for(int j=0; j<=5; ++j){
cout<<k[i][j]<<" "<<"\t";
k[i][j]=0;}
cout<<"\n\n";}

cout<<" Transpose of Matrix [A]= "<<"\n\n";
for(int i=0; i<=5; ++i)
{for(int j=0; j<=5; ++j)
{cout<<s[i][j]<<" "<<"\t";
s[i][j]=0;}
cout<<"\n\n";}

//******************************************************

cout<<"\t\t Value of Mass Matrix :"<<"\n\n";

for(int i=0; i<6; i++){
for(int j=0; j<6; j++){
for(int k=0; k<=5; k++){

d[i][j]=d[i][j]+(k[i][k]*s[k][j]);
d[i][j]=0;}}}

cout<<"your matrix is"<<endl;
for(int i=0;i<6;i++){
for(int j=0;j<6;j++){
cout<<d[i][j]<<" ";
}cout<<endl;}
//system("pause");

cin>>y4;
return 0;}
compiler shows error message
what is the error message?
C:\Users\CAD_6\Desktop\C++ Program\mi7.cpp In function `int main()':
48 C:\Users\CAD_6\Desktop\C++ Program\mi7.cpp invalid types `int[int]' for array subscript
array k conflicts with int k
Thanks now its working
Topic archived. No new replies allowed.