السلام عليكم جميعا اخوتي ...
لدي برنامج (ساعدني فيه اخ كريم ) في جزء من هذا البرنامج عمليه ضرب مصفوفتين , المشكله اني عندما اعطي البرنامج قيم المصفوفتين 0و1(مصفوفات بولينيه) الخرج يكون قيم غير ال0و1
مع العلم اني في البرنامج كتبت شرط للمصفوفه البولينيه ولكن :sad: لا يحقق .
الشرط في البرنامج هكذا
sum = 0;
if (sum > 1)
{
sum = 1;و هذا هو البرنامج ..
#include <cstdlib>
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
int row, col, mult[10][10], k, sum ;
/////////////////////////////////////////////////////////////////////////////
cout << endl << "--------------------The Boalen A matrix------------------------------" << endl;
int a_rows = 0, a_cols = 0;
cout << "Please enter rows: ";
cin >> a_rows;
cout << "Please enter cols: ";
cin >> a_cols;
int *pnewrow;
int **A = new int * [a_rows];
int i, x;
for (i = 0; i < a_rows; i++)
{
pnewrow = new int[a_cols];
*(A + i) = pnewrow;
for (x = 0; x < a_cols; x++)
{
cout << "Row: " << i + 1 << " Col: " << x + 1 << ": ";
cin >> *(*(A + i) + x); // or cin >> *(pnewrow+x);
}
}
//////////////////////////////////////////////////////////////////////////////
cout << endl << "--------------------The Boalen B matrix------------------------------" << endl;
int b_rows = 0, b_cols = 0;
cout << "Please enter rows: ";
cin >> b_rows;
cout << "Please enter cols: ";
cin >> b_cols;
int **B = new int * [b_rows];
for (i = 0; i < b_rows; i++)
{
pnewrow = new int[b_cols];
*(B + i) = pnewrow;
for (x = 0; x < b_cols; x++)
{
cout << "Row: " << i + 1 << " Col: " << x + 1 << ": ";
cin >> *(*(B + i) + x); // or cin >> *(pnewrow+x);
}
}
//////////////////////////////////////////////////////////////////////////////////
// TRANSPOSE A matrix
int t_a_rows = a_cols, t_a_cols = a_rows;
int **t_A = new int * [t_a_rows];
for (i = 0; i < t_a_rows; i++)
{
pnewrow = new int[t_a_cols];
*(t_A + i) = pnewrow;
for (x = 0; x < t_a_cols; x++)
*(*(t_A + i) + x) = *(*(A + x) + i); // or cin >> *(pnewrow+x); }
}// end of Transpose A
////////////////////////////////////////////////////////////////////////////////
///INVERSE B
// == 0 --------> 1
// <> 0 --------> 0
int temp = 0;
for (i = 0; i < b_rows; i++)
for (x = 0; x < b_cols; x++)
{
temp = *(*(B + i) + x);
*(*(B + i) + x) = (temp == 0) ? 1 : 0; // or cin >> *(pnewrow+x);
}
///end INVERSE B
// test programs:
cout << "Transpose " << endl;
for (i = 0; i < t_a_rows; i++)
{
for (x = 0; x < t_a_cols; x++)
cout << *(*(t_A + i) + x) << " "; // or cin >> *(pnewrow+x); }
cout << endl;
}// end test of Transpose A
cout << "INVERSE" << endl;
for (i = 0; i < b_rows; i++)
{
for (x = 0; x < b_cols; x++)
cout << *(*(B + i) + x) << " "; // or cin >> *(pnewrow+x);
cout << endl;
} // end test of Inverse B
/////////////////////////////////////////////////////////////////
// Multiply Transpose A & Inverse B (M matrix)
int k_rows =0, k_cols = 0;
int INVERSE[10][10];
int Transpose[10][10] ;
if(b_rows==a_cols)
{
sum = 0;
if (sum > 1)
{
sum = 1;
for(i=0;i<a_rows;i++)
{
for(x=0;x<b_cols;x++)
{
// mult[x]=0;
for(k=0;k<a_rows;k++)
{
// mult[x]= mult[x] + Transpose[k] * INVERSE[k][x];
//cout << mult[x] << " "; // or cin >> *(pnewrow+x);
sum = sum + Transpose[k]*INVERSE[k][x];
}
mult[x] = sum;
}
}
}
}
cout << "Now we multiply both the above matrix" << endl;
for ( i = 0 ; i <a_rows ; i++ )
{
for ( x = 0 ; x < b_cols ; x++ )
cout << mult[x] << " ";
cout << endl;
}
//else
// {
// printf("Matrix multiplication cannot be done");
//}
/////////////////////////////////////
///INVERSE
// == 0 --------> 1
// <> 0 --------> 0
int **K = new int * [k_rows];
int temp2 = 0;
for (i = 0; i < k_rows; i++)
for (x = 0; x < k_cols; x++)
{
temp2 = *(*(K + i) + x);
*(*(K + i) + x) = (temp2 == 0) ? 1 : 0; // or cin >> *(pnewrow+x);
}
///end INVERSE K
cout << "INVERSE K" << endl;
for (i = 0; i < k_rows; i++)
{
for (x = 0; x < k_cols; x++)
cout << *(*(K + i) + x) << " "; // or cin >> *(pnewrow+x);
cout << endl;
} // end test of Inverse B
getchar();
getchar();
return 0;
}
=';اما المخرجات فتكون ...
--------------------The Boalen A matrix------------------------ Please enter rows: 2 Please enter cols: 3 Row: 1 Col: 1: 0 Row: 1 Col: 2: 1 Row: 1 Col: 3: 0 Row: 2 Col: 1: 1 Row: 2 Col: 2: 0 Row: 2 Col: 3: 1 --------------------The Boalen B matrix------------------------ Please enter rows: 2 Please enter cols: 2 Row: 1 Col: 1: 0 Row: 1 Col: 2: 0 Row: 2 Col: 1: 1 Row: 2 Col: 2: 1 Transpose 0 1 1 0 0 1 INVERSE 1 1 0 0 Now we multiply both the above matrix -858993460 -858993460 -858993460 -858993460 INVERSE K



