Matritsalarni ko’paytirish algoritmi Matritsa-matritsani ko'paytirish muammosi munosabatlar bilan belgilanadi
.
masala. Ikkita matritsa berilgan. Ularning ko’paytmasini toppish algoritmi va dasturini tuzing.
Dastur kodi. #include using namespace std;//ulchamlari bir xil bulgan matritsalar uchun
int main()
{
int a[10][10],b[10][10],c[10][10],r,d,i,j,k;
cout<<"satrlar soni=";
cin>>r;
cout<<"ustunlar soni=";
cin>>d;
cout<<"matritsa elementlarini kiriting=\n";
for(i=1;i<=r;i++)
{ for(j=1;j<=d;j++) {
cin>>a[i][j];} }
cout<<"ikkinchi matritsa elementlarini kiriting=\n";
for(i=1;i<=r;i++)
{ for(j=1;j<=d;j++)
cin>>b[i][j];}
for(i=1;i<=r;i++)
{ for(j=1;j<=d;j++)
{ c[i][j]=0;
for(k=1;k<=d;k++)
{
c[i][j]+=a[i][k]*b[k][j]; } } }
//natijani chop qilish
for(i=1;i<=r;i++)
{
for(j=1;j<=d;j++)
{
cout<}
cout<<"\n";
}
return 0;
}
Scanner in =new Scanner(System.in);
Random random= new Random();
int a [][] = new int[3][3];
System.out.println("A matritsa satrini kiriting: ");
int n= in.nextInt();
System.out.println("A matritsa ustunini kiriting: ");
int m= in.nextInt();
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
a[i][j]= random.nextInt(10);
}
System.out.println();
}
int[][] b = new int[3][3];
System.out.println("B matritsa satrini kiriting: ");
int k = in.nextInt();
System.out.println("B matritsa ustunini kiriting: ");
int l = in.nextInt();
System.out.println("B matritsa elementlari: ");
for (int i = 0; i < k; i++) {
for (int j = 0; j < l; j++) {
b[i][j]= random.nextInt(10);
System.out.println("B matritsa elementlari: " + b[i][j]);
}
System.out.println();
}
int[][] c = new int[3][3];
for (int i = 0; i < n; i++) {
for (int j = 0; j <= 1; j++) {
c[i][j] =0;
for (int p = 0; p < k; p++) {
c[i][j] += a[i][p] * b[p][j];