1. ## fatal error

hello!

Unresolved external symbol '_printA'.
POLINK: error: Unresolved external symbol '_printO'.
POLINK: fatal error: 2 unresolved external(s).

Code:
```#include <stdio.h>
#include <math.h>

void scaling(double* P[],double B[], int i,  int j,int order);

void PrintA(double A[30][30], int m,int n);

void PrintO(double* O[30], double B[30],int m,int n);

int main()
{
double A[30][30];
double B[30];
double* O[30];
int i,j,m,n,order;

printf("enter the number of rows and columns: \n");
scanf("%d%d",&i,&j);
printf("enter %d*%d matrix\n:",i,j);

for (m=0 ; m<i ; m++)
for(n=0 ; n<j ; n++)
scanf("%lf",&(A[m][n]));

printf("enter %d vector: \n",i);

for (m=0 ; m<i ; m++)
scanf("%lf",&(B[m]));

for(order=0;order<i;order++);
{
scaling(O,B,i,j,order);
printA(A,i,j);
printO(O,B,i,j);
}
return 0;
}

void scaling(double* P[],double B[], int i,  int j,int order)
{
int m,n,maxrow;
double max[30], maxi=0,temp2;
double* temp;
for (m=order;m<i;m++)
for(n=order;n<j && fabs(P[m][n])>max[m];n++)
max[m]=fabs(P[m][n]);
for (m=order;m<i;m++)
if ((fabs(P[m][order])/max[m])>maxi)
{
maxi=(fabs(P[m][order]/max[m]));
maxrow=m;
}
if(maxrow!=order)
{
temp=P[maxrow];
P[maxrow]=P[order];
P[order]=temp;

temp2=B[maxrow];
B[maxrow]=B[order];
B[order]=temp2;

}

}

void PrintA(double A[30][30], int m,int n)
{
int i,j;

printf("original coefficients matrix:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%.2lf ",A[i][j]);

printf("\n");
}
printf("\n");
}

void PrintO(double* O[30], double B[30], int m,int n)
{
int i,j;

printf("current matrix:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%.2lf ",O[i][j]);
printf("| %.2lf",B[i]);
printf("\n");
}
printf("\n");
}```
thank!

2. printA is different from PrintA, and similarly printO is different from PrintO.

3. ## tanks now i have a run time error

hello' thank you for the answer!
i have a run time error now....
it stops when it spouse to print marix O.
Code:
```#include <stdio.h>
#include <math.h>

void scaling(double* P[],double B[], int i,  int j,int order);

void printA(double A[30][30], int m,int n);

void printO(double* O[30], double B[30],int m,int n);

int main()
{
double A[30][30];
double B[30];
double* O[30];
int i,j,m,n,order;

printf("enter the number of rows and columns: \n");
scanf("%d%d",&i,&j);
printf("enter %d*%d matrix\n:",i,j);

for (m=0 ; m<i ; m++)
for(n=0 ; n<j ; n++)
scanf("%lf",&(A[m][n]));

printf("enter %d vector: \n",i);

for (m=0 ; m<i ; m++)
scanf("%lf",&(B[m]));

for(order=0;order<i;order++);
{
scaling(O,B,i,j,order);
printA(A,i,j);
printO(O,B,i,j);
}
return 0;
}

void scaling(double* P[],double B[], int i,  int j,int order)
{
int m,n,maxrow;
double max[30], maxi=0,temp2;
double* temp;
for (m=order;m<i;m++)
for(n=order;n<j && fabs(P[m][n])>max[m];n++)
max[m]=fabs(P[m][n]);
for (m=order;m<i;m++)
if ((fabs(P[m][order])/max[m])>maxi)
{
maxi=(fabs(P[m][order]/max[m]));
maxrow=m;
}
if(maxrow!=order)
{
temp=P[maxrow];
P[maxrow]=P[order];
P[order]=temp;

temp2=B[maxrow];
B[maxrow]=B[order];
B[order]=temp2;

}

}

void printA(double A[30][30], int m,int n)
{
int i,j;

printf("original coefficients matrix:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%.2lf ",A[i][j]);

printf("\n");
}
printf("\n");
}

void printO(double* O[30], double B[30], int m,int n)
{
int i,j;

printf("current matrix:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%f ",O[i][j]);
printf("| %f",B[i]);
printf("\n");
}
printf("\n");
}```

4. ## a run time error

hi!

i have a run time error, i tried to fix it but i failed....

i think its about the scaling func.

Code:
```#include <stdio.h>
#include <math.h>

void scaling(double* P[],double B[], int i,  int j,int order);

void printA(double A[30][30], int m,int n);

void printO(double* O[30], double B[30],int m,int n);

void calc(double* O[30], double B[30], int m,int n,int order);

int main()
{
double A[30][30];
double B[30];
double* O[30];
int i,j,m,n,order;

printf("enter the number of rows and columns: \n");
scanf("%d%d",&i,&j);
printf("enter %d*%d matrix\n:",i,j);

for (m=0 ; m<i ; m++)
for(n=0 ; n<j ; n++)
scanf("%lf",&(A[m][n]));

printf("enter %d vector: \n",i);

for (m=0 ; m<i ; m++)
scanf("%lf",&(B[m]));

for(order=0;order<i;order++);
{
scaling(O,B,i,j,order);
calc(O,B,i,j,order);
printA(A,i,j);
printO(O,B,i,j);
}
return 0;
}

void scaling(double* P[],double B[], int i,  int j,int order)
{
int m,n,maxrow;
double max[30], maxi=0,temp2;
double* temp;
for(m=order;m<i;m++)
max[m]=0;

for (m=order;m<i;m++)
for(n=order;n<j;n++)
if (max[m]< fabs(P[m][n]))
max[m]=fabs(P[m][n]);
for (m=order;m<i;m++)
if ((fabs(P[m][order])/max[m])>maxi)
{
maxi=(fabs(P[m][order]/max[m]));
maxrow=m;
}
if(maxrow!=order)
{
temp=P[maxrow];
P[maxrow]=P[order];
P[order]=temp;

temp2=B[maxrow];
B[maxrow]=B[order];
B[order]=temp2;

}

}

void printA(double A[30][30], int m,int n)
{
int i,j;

printf("original coefficients matrix:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%.2lf ",A[i][j]);

printf("\n");
}
printf("\n");
}

void printO(double* O[30], double B[30], int m,int n)
{
int i,j;

printf("current matrix:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%f ",O[i][j]);
printf("| %f",B[i]);
printf("\n");
}
printf("\n");
}

void calc(double* O[30], double B[30], int m,int n,int order)
{
int i,j;

for (i=order;i<m-1;i++);
{
for (j=order;j<n;j++);
O[i+1][j]=O[i+1][j]-O[order][j]*O[order+1][order]/O[order][order];
}
}```

5. Calling variables "O" is a very BAD THING, because it makes them look so similar to the digit "0".

When running your program with 2x2 matrix with the values 1, 2, 3, 4 and 1, 2 in the vector, it crashes with a NULL memory access here (at what seems to be O[1][1] ??):
Code:
`    O[i+1][j]=O[i+1][j]-O[order][j]*O[order+1][order]/O[order][order];`
I'm not entirely surprised at that, since O is an array of pointer, and you do not call malloc [or similar functions] in your code.

--
Mats

6. Agreed.

- Single letter identifiers.
- poorly indented code.
Neither are good when it comes to getting others to look at your code.

7. hi,
I'm doing this work with Miri.
We fixed the 0-O mistake. It makes the run time error come a bit later...
Anybody can figure out why it won't work?

Thank you.

8. Originally Posted by Livnat
hi,
I'm doing this work with Miri.
We fixed the 0-O mistake. It makes the run time error come a bit later...
Anybody can figure out why it won't work?

Thank you.
Given that we have no idea what the new code looks like, how do you think we can know what is going wrong?

--
Mats

9. I t looks pretty much the same. We changed the O's and the 0's to P's. Maybe we should change all the names to something more meaningful like you suggested . In the meantime, here's the code:

Code:
```#include <stdio.h>
#include <math.h>

void scaling(double* P[],double B[], int i,  int j,int order);

void printA(double A[30][30], int m,int n);

void printP(double* P[30], double B[30],int m,int n);

void calc(double* P[30], double B[30], int m,int n,int order);

int main()
{
double A[30][30];
double B[30];
double* P[30];
int i,j,m,n,order;

printf("enter the number of rows and columns: \n");
scanf("&#37;d%d",&i,&j);
printf("enter %d*%d matrix\n:",i,j);

for (m=0 ; m<i ; m++)
for(n=0 ; n<j ; n++)
scanf("%lf",&(A[m][n]));

printf("enter %d vector: \n",i);

for (m=0 ; m<i ; m++)
scanf("%lf",&(B[m]));

for(order=0;order<i;order++);
{
scaling(P,B,i,j,order);
calc(P,B,i,j,order);
printA(A,i,j);
printP(P,B,i,j);
}
return 0;
}

void scaling(double* P[],double B[], int i,  int j,int order)
{
int m,n,maxrow;
double max[30], maxi=0,temp2;
double* temp;
for(m=order;m<i;m++)
max[m]=0;

for (m=order;m<i;m++)
for(n=order;n<j;n++)
if (max[m]< fabs(P[m][n]))
max[m]=fabs(P[m][n]);
for (m=order;m<i;m++)
if ((fabs(P[m][order])/max[m])>maxi)
{
maxi=(fabs(P[m][order]/max[m]));
maxrow=m;
}
if(maxrow!=order)
{
temp=P[maxrow];
P[maxrow]=P[order];
P[order]=temp;

temp2=B[maxrow];
B[maxrow]=B[order];
B[order]=temp2;

}

}

void printA(double A[30][30], int m,int n)
{
int i,j;

printf("original coefficients matrix:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%.2lf ",A[i][j]);

printf("\n");
}
printf("\n");
}

void printP(double* P[30], double B[30], int m,int n)
{
int i,j;

printf("current matrix:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%f ",P[i][j]);
printf("| %f",B[i]);
printf("\n");
}
printf("\n");
}

void calc(double* P[30], double B[30], int m,int n,int order)
{
int i,j;

for (i=order;i<m-1;i++);
{
for (j=order;j<n;j++);
P[i+1][j]=(P[i+1][j]-P[order][j]*P[order+1][order]/P[order][order]);
}
}```
Thanks...

10. So what is your P array pointing to? You only fixed the first of my two suggestions.

--
Mats

11. ## problematic loop

hi thank you!

to simplify the problem, here is the problematic loop:

Code:
```void diagonal(double* P[30], double B[30], int m,int n,int order)//diagonal b!!
{
int i,j,k;
printf("im alive\n");
for (i=order;i<m;i++)
for (j=0;j<order;j++)
for (k=1;k<m+1-order;k++)
P[i+k][j]=(P[i+k][j]-P[order][j]*P[order+k][order]/P[order][order]);
printf("im alive\n");
}```

and this is the intire code:
Code:
```#include <stdio.h>
#include <math.h>

void scaling(double* P[],double B[], int i,  int j,int order);

void printA(double A[30][30], int m,int n);

void printP(double* P[30], double B[30],int m,int n);

void diagonal(double* P[30], double B[30], int m,int n,int order);

void calc(double* P[30], double B[30], int m,int n);

int main()
{
double A[30][30];
double B[30];
double* P[30];
int i,j,m,n,order;

printf("enter the order of the matrix: \n");
scanf("%d",&i);
printf("enter %d*%d matrix:\n",i,i);
j=i;
for (m=0 ; m<i ; m++)
for(n=0 ; n<j ; n++)
scanf("%lf",&(A[m][n]));

printf("enter %d vector: \n",i);

for (m=0 ; m<i ; m++)
scanf("%lf",&(B[m]));

for (m=0;m<i;m++)
P[m]=A[m];
printP(P, B, m, n);

for(order=0;order<i;order++)
{
scaling(P,B,i,j,order);
printA(A,i,j);
printP(P,B,i,j);
diagonal(P,B,i,j,order);
printA(A,i,j);
printP(P,B,i,j);
}
calc(P, B,  m, n);
return 0;
}

void scaling(double* P[],double B[], int i,  int j,int order)
{
int m,n,maxrow;
double max[30], maxi=0,temp2;
double* temp;
for(m=order;m<i;m++)
max[m]=0;

for(m=order;m<i;m++)
printf("%f",max[m]);

for (m=order;m<i;m++)
for(n=order;n<j;n++)
if (max[m]< fabs(P[m][n]))
{
max[m]=fabs(P[m][n]);
printf("max%d=%f\n",m,max[m]);
}
for (m=order;m<i;m++)
if ((fabs(P[m][order])/max[m])>maxi)
{
maxi=(fabs(P[m][order]/max[m]));
maxrow=m;
}
if(maxrow!=order)
{
temp=P[maxrow];
P[maxrow]=P[order];
P[order]=temp;

temp2=B[maxrow];
B[maxrow]=B[order];
B[order]=temp2;

}

}

void printA(double A[30][30], int m,int n)
{
int i,j;

printf("original coefficients matrix:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%.2lf ",A[i][j]);

printf("\n");
}
printf("\n");
}

void printP(double* P[30], double B[30], int m,int n)
{
int i,j;

printf("current matrix:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%f ",P[i][j]);
printf("| %f",B[i]);
printf("\n");
}
printf("\n");
}

void diagonal(double* P[30], double B[30], int m,int n,int order)//diagonal b!!
{
int i,j,k;
printf("im alive\n");
for (i=order;i<m;i++)
for (j=0;j<order;j++)
for (k=1;k<m+1-order;k++)
P[i+k][j]=(P[i+k][j]-P[order][j]*P[order+k][order]/P[order][order]);
printf("im alive\n");
}

void calc(double* P[30], double B[30], int m,int n)
{
int i,j;
double x[30],y[30];
for (i=0;i<m;i++)
y[i]=B[i];
for (i=0;i<m;i++)
x[i]=0;
for (i=m;i>0;i--)
{
for (j=m;j>i;j--)
y[i]-=P[i][j]*x[j];
x[i]=y[i]/P[i][i];
printf("x[%d]=%f",i,x[i]);
}
}```
we still have a run time error....

thanks,
miri & livnat

12. when i = m-1
k = m-order
i+k = 2m-order-1

when order = 0 you are accessing index 2m-1 which could be way out of bounds

I suppose other combinations of indexes are also bloated...

13. thank you Vart.
we did some adjestmants, here is the new loop...

Code:
```void diagonal(double* P[30], double B[30], int m,int n,int order)//diagonal b!!
{
int j,k;
printf("im alive\n");
for (k=1;k<m+1-order;k++)
for (j=0;j<m;j++)
P[k+order][j+order]=(P[k+order][j+order]-P[order][j+order]*P[order+k][order]/P[order][order]);
printf("im not alive\n");
}```

14. ## we got it :)

this is the fixed loop:

Code:
```void diagonal(double* P[30],double B[30],int m,int order)//diagonal b!!
{
int j,k;
for (k=1;k<m-order;k++)
for (j=0;j<m;j++)
P[k+order][j+order]=(P[k+order][j+order]-P[order][j+order]*P[order+k][order]/P[order][order]);

}```
the hole code still doesn't work peoperly,,,
we'll be back ....

15. j+order could be bigger than m
in your inner loop - add the index checks with assert or printf
Code:
```if(k+order <0 || k+order >= m) printf("k+order(&#37;d) error", k+order);
if(j+order<0 || j+order>= m) printf("j+order(%d) error", j+order);
if(order <0 || order >= m) printf("order(%d) error", order);```
for each index you are using...