#include <iostream>
using namespace std ;
int main ()
{
int i,j,k,sum ;
int a[2][2],b[2][2] ;
for (i=0; i<2; i++)
{
for (j=0; j<2; j++)
{
cout << "Enter for " << "a[" << i << "][" << j << "]" << " element";
cin >> a[j];
}
}
cout << endl << endl;
for (i=0; i<2; i++){ // this is for b
for (j=0; j<2; j++){
cout << "Enter for" << "b[" << i << "][" << j << "]" << " element" ;
cin >> b[j];
}
}
cout << "Now you see here that you typed for Matrix a" << endl << endl;
cout << "********************************************" << endl << endl;
for (i=0; i<2; i++)
{
for (j=0; j<2; j++)
{
cout << a[j] << '\t';
}
cout << endl << endl ;
}
cout << endl << endl;
cout << "Now you see here that you typed for Matrix b" << endl<<endl;
cout << "*********************************************" <<endl << endl;
for (i=0; i<2; i++)
{
for (j=0; j<2; j++)
{
cout << b[j] << '\t';
}
cout << endl << endl;
}
cout << "\n";
cout << "Now you see here the multiplication of Matrix a and b" << endl<< endl ;
cout << "+******************************************************+" << endl << endl ;
for (i =0; i<2; i++)
{
for (j=0; j<2; j++)
{
sum = 0;
for (k=0; k<2; k++){
sum = sum + a[k] * b[k][j];
}
cout << sum << '\t';
}
cout << endl << endl;
}
return 0;
}الكود شغال مية المية
لكن الاستفسار
cout << "Now you see here the multiplication of Matrix a and b" << endl<< endl ;
cout << "+******************************************************+" << endl << endl ;
for (i =0; i<2; i++)
{
for (j=0; j<2; j++)
{
sum = 0;
for (k=0; k<2; k++){
sum = sum + a[k] * b[k][j];
}
cout << sum << '\t';
}
cout << endl << endl;
}
return 0;كيفية عمل الكود هنا كيف سيسير البرنامج ؟
