using namespace std;
int main()
{
int a,b,c,d,i,j,k;
cout<<"kaca kaclik bir matris carpimi istiyorsunuz"<<endl;
cout<<"1.matrisin satir sayisi :";
cin>>a;
cout<<"1.matrisin sutun sayisi :";
cin>>b;
cout<<"2.matrisin satir sayisi :";
cin>>c;
cout<<"2.matrisin sutun sayisi :";
cin>>d;
int mata[a][b],matb[c][d], matc[a][d];
cout<<endl;
if(b != c)
{
cout<<"1. matrisin sutun sayisi 2. matrisin satir sayisina eşit olmali"<<endl;
return 0;
}
cout<<"============================================"<<endl;
cout<<"birinci matrisin sayilarini girin"<<endl;
for(i=0; i<a; i++)
{
for(j=0; j<b; j++)
{
cout<<"a["<<i<<"]["<<j<<"] = ";
cin>>mata[i][j];
}
cout<<endl;
}
cout<<"=========================================="<<endl;
cout<<"ikinci matrisin sayilarini girin"<<endl;
for(i=0; i<c; i++)
{
for(j=0; j<d; j++)
{
cout<<"b["<<i<<"]["<<j<<"] = ";
cin>>matb[i][j];
}
cout<<endl;
}
cout<<endl<<endl;
for(i=0; i<a; i++)
{
for(j=0; j<b; j++)
cout<<mata[i][j]<<"\t";
cout<<endl;
}
cout<<"==========================================="<<endl;;
for(i=0; i<c; i++)
{
for(j=0; j<d; j++)
cout<<matb[i][j]<<"\t";
cout<<endl;
}
cout<<"===========carpim sonucu=================="<<endl;
for(i=0; i<a; i++)
for(j=0; j<d; j++)
matc[i][j]=0;
for(i=0; i<a; i++)
for(j=0; j<d; j++)
for(k=0; k<b; k++)
matc[i][j] += mata[i][k]*matb[k][j];
cout<<endl<<endl;
for(i=0; i<a; i++)
{
for(j=0; j<d; j++)
cout<<matc[i][j]<<"\t";
cout<<endl;
}
return 0;
}
Hiç yorum yok:
Yorum Gönder