Code:
static int transformacija(int n, int[][] x)
{
int a, b, p = 1;
for(int i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
if ((x[i][i] > 0 && x[j][i] > 0) || (x[i][i] < 0 && x[j][i] < 0))
{
a = -1 * x[i][i];
b = x[j][i];
p = p * a;
for (int t = 0; t < n; t++)
x[j][t] = b * x[i][t] + a * x[j][t];
}
else
{
a = x[i][i];
b = x[j][i];
p = p * a;
for (int t = 0; t < n; t++)
x[j][t] = b * x[i][t] + a * x[j][t];
}
int del = p;
p=1;
for (int i = 0; i < n; i++)
p = p * x[i][i];
return p / del;
}
static int transformacija(int n, int[][] x)
{
int a, b, p = 1;
for(int i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
if ((x[i][i] > 0 && x[j][i] > 0) || (x[i][i] < 0 && x[j][i] < 0))
{
a = -1 * x[i][i];
b = x[j][i];
p = p * a;
for (int t = 0; t < n; t++)
x[j][t] = b * x[i][t] + a * x[j][t];
}
else
{
a = x[i][i];
b = x[j][i];
p = p * a;
for (int t = 0; t < n; t++)
x[j][t] = b * x[i][t] + a * x[j][t];
}
int del = p;
p=1;
for (int i = 0; i < n; i++)
p = p * x[i][i];
return p / del;
}
f-ju pozivam ovako u programu:
Code:
Console.Write("resenje je: " + transformacija(n,a).ToString()+"\n");
Console.Write("resenje je: " + transformacija(n,a).ToString()+"\n");
a mi je int[][], a n mi je int
hvala uapred