برنامه ضرب دو ماتریسa×b *b×c - هفت خط کد انجمن پرسش و پاسخ برنامه نویسی

برنامه ضرب دو ماتریسa×b *b×c

+1 امتیاز

سلام. دوستان میشه بگید مشکل این کد چیه؟ 


#include <iostream>
using namespace std;
 
int main() {
   

   
    int a, b, c;
   

    cin>>a>>b>>c;
    int m1[a][b], m2[b][c], m3[a][c] = {0};
   

    for(int i = 0; i <a; i++){
        for(int j = 0; j < b; j++){
           
            cin>>m1[i][j];
        }       
    }
   

    for(int i = 0; i < b; i++){
        for(int j = 0; j < c; j++){
       
            cin>>m2[i][j];
        }       
    }
   
   
    for(int i = 0; i < a; i++){
        for( int j = 0; j < c; j++){
            for(int k = 0; k < b; k++)
                m3[i][j] += m1[i][k] * m2[k][j];
               
            cout<<m3[i][j]<<"  ";
        }
        cout<<endl;   
    }
   
   
   
    return 0;
}

 

 

سوال شده دی 4, 1398  بوسیله ی Mrg78 (امتیاز 16)   2 3
ویرایش شده دی 5, 1398 بوسیله ی مصطفی ساتکی

1 پاسخ

0 امتیاز

با این مفایسه کن

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
 int n,m;
float a[100][100],b[100][100],c[100][100]; // a=matris 1 _ b=matris 2 _ c=hasel
int i,j,k;
//khandan matris 1
cout<<"enter matris 1 : "<<endl;
cin>>n>>m;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
cin>>a[i][j];
//khandan matris 2
cout<<"enter matris 2 : "<<endl;
cin>>n>>m;
for(i=0;i<n;i++)
for(j=0;j<m;j++)
cin>>b[i][j];
//neveshtan matris 1
cout<<"matris 1 : "<<endl;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
cout<<a[i][j]<<" ";
cout<<endl;
}
//neveshtan matris 2
cout<<"matris 2 : "<<endl;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
cout<<b[i][j]<<" ";
cout<<endl;
}
//hasel zarb
for(i=0;i<n;i++)
for(j=0;j<m;j++)
{
c[i][j]=0;
for(k=0;k<2;k++)
c[i][j]+=a[i][k]*b[k][j];
}
//neveshtane hasel zarb
cout<<"hasel zarb : "<<endl;
for(i=0;i<n;i++)
{
cout.width(10);
for(j=0;j<m;j++)
cout<<c[i][j]<<" ";
cout<<endl;
}
}

 

پاسخ داده شده دی 6, 1398 بوسیله ی tavarish60 (امتیاز 14)   1 1 1
ویرایش شده دی 6, 1398 بوسیله ی tavarish60
...