please suggest me solution

I am trying to multiply 2 matrix of 6x6. But in Result i am getting 00000.....


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
#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<<"Value of Mass Matrix :"<<"\n\n";
 for(int i=0; i<=5; i++){
        for(int j=0; j<=5; j++){
          for(int p=0; p<=5; p++){
          d[i][j]=0;
          d[i][j]=(k[i][p]*s[p][j])+d[i][j];
          }}}  
             
cout<<"Mass Matrix =:"<<"\n";                
{for(int i=0;i<=5;i++)
 for(int j=0;j<=5;j++){
cout<<"\t\t"<<d[i][j];
}cout<<"\n";}
return0;
}
I recommend stepping through the code with a debugger. You'll be able to see the state of all your variables at every step. This should help you see why you're getting the results you're seeing.
Does line 24 make sense?

Andy
what data type should i use

if i delete line 24 output is different.
Move line 24 before line 23
which data type should i use for matrix multiplication. I want to minimize digits after decimal.
since you want decimal, you use float and you can use
std::setprecision() if you want to set the width of the decimals to be displayed.

you need to #include <iomanip>
Topic archived. No new replies allowed.