مساء الخير
انابعمل project ++c لحساب matrix وكل شوية يطلع error وده المشرع
#include"stdio.h"
#include"conio.h"
struct Matrix
{
int n;
int m;
double*M;
};
void MFree(struct Matrix*p)
{ //we should free the array M
if(p->M!=0);
//M is a pointer variable to the array,so if it is null then the array wasnot allocated
}
void MCreate(struct Matrix*p,int rows,int cols);
{
MFree(p);
p->n=rows;
p->m=cols;
p->M=(double*)malloc((p->n*P->m)*sizeof(double));
}
void MScan(struct Matrix*p);
{
for(int i=0;i<(p->n)*(p->m);i++)
scanf("%lf",&(p->m);i++)
scanf("%lf",&(p->M));
}
void MPrint(struct Matrix*p)
{printf("\n the matrix values :\n");
for(int i=0;i<(p->n)*(p->m);i++)
{
if(i%(p->m)==0)
printf("\n");
printf("%lf\t",p->M);
}
}
double MGet(struct Matrix*p,int r,int c)
{
double a=p->M[(r*p->m)+c];
return a;
}
void MSet(struct Matrix*p,int r,int c,double value)
{
p->M[(r*p->m)+c]=value;
}
void Madd(struct Matrix*px,struct Matrix*py,struct Matrix*pz);
{
if
(px->n)==(py->n)&&(px->m)==(px->m))
{
MCreate(pz,px->n,px->m);
for(int i=0;i<(px->n*px->m);i++)
pz->M=(px->M+(py->M);
Printf("\n\nThe sum of the2matrices:");
MPrint(pz);
}
else
printf("\n\nError:the 2 matrices don't match in size to be added.\n");
}
void MTrans(struct Matrix*px,struct Matrix*pz)
{
double value;
MCreate(pz,px->n,px->m);
for(int i=0;i<(px->n);i++)
{
for(int j=0;j<(px->m);j++)
{
value=MGet(pz,i,j);
MSet(pz,j,i,value);
}
}
printf("\n\n The Transpose of the matrix:");
MPrint(pz);
}
void MMul(struct Matrix*px,struct Matrix*py,struct Matrix*pz)
{
double a;
if((px->m)==(py->n));
{
MCreate(pz,px->m,py->m);
for(int i=0;i<(px->n);i++)
{
for(int j=0;j<(py->m);j++)
{
a=0;
for(int k=0;k<(px->m);k++)
{
a+=MGet(px,i,k)*MGet(py,k,j);
}
MSet(pz,i,j,a);
}
}
printf("\n\n The product of the 2 matrices:");
MPrint(pz);
}
}
ارجو المساعدة
