1 / 2
Dec 2019

void eliminare_Gauss(double A[][100], double B[], int n)
{
for (int i = 1; i <= n; i++)
{
double aux = A[i][i];
for (int j = i; j <= n; j++)
{
A[i][j] = A[i][j] / aux;
B[i] = B[i] / aux;
}
for (int k = i + 1; k <= n; k++)
{
double aux = A[j][i];
for (int j = i; j <= n; j++)
{
A[k][j] = A[k][k] - A[i][j] * aux;
B[k] = B[k] - B[i] * aux;
}
}

}

}
void afisare_matrice(double A[][100], int n)
{
int i, j;
for (i;i<=n;i++)
{
for(j;j<=n;j++)
{
printf("",);
}
}
}
void rezolvare_tri(double A[][100], double V[], double B[], int n)
{
for (int i = n; i >= 1; i–)
{
V[i] = B[i];
for (int j = i + 1; j <= n; j++)
{
V[i] =A[i][j] * V[j];
V[i] /= A[i][i];
}
}
}

int main(int agrc, char*** argv)
{

double A[5][5], V[6], B[5], R[8], E, I1,I7, Rech;
int i, n;

E = 3.0;
R[1] = R[2] = R[3] = R[4] = R[5] = R[6] = R[7] = 1;
A[1][1] = 1 / R[1] + 1 / R[2] + 1 / R[3];
A[1][2] = -1 / R[2];
A[1][3] = -1 / R[3];
A[1][4] = 0;
A[2][1] = -1 / R[2];
A[2][2] = 1 / R[2] + 1 / R[4] + 1 / R[6];
A[2][3] = -1 / R[6];
A[2][4] = -1 / R[4];
A[3][1] = -1 / R[3];
A[3][2] = -1 / R[6];
A[3][3] = 1 / R[3] + 1 / R[5] + 1 / R[6];
A[3][4] = -1 / R[5];
A[4][1] = 0;
A[4][2] = -1 / R[4];
A[4][3] = -1 / R[5];
A[4][4] = 1 / R[4] + 1 / R[5] + 1 / R[7];
B[1] = E / R[1];
B[2] = B[3] = B[4] = 0.0;

eliminare_Gauss(A, B, n);

afisare_matrice(A, n);
for (i = 1; i <= n; i++)
	printf("%f", B[i]);

rezolvare_tri(A, V, B, n);

printf("\n\n\n");
for (i=0; i <= 5; i++)
{
	printf("V[%d]=%f\n", i, V[i]);
}

I1 = (V[0] - V[1] / R[1]);
I7 = (V[4] - V[5] / R[7]);

    printf("\n\nCurentul la intrare este %f.\n",I1);
    pruntf("\n\nCurentul la iesire este %f.\n",I7);

    Rech = E / I1;
printf("\n Rezistenta echivalenta este : %d ", Rech);

return 0;

}

  • created

    Dec '19
  • last reply

    Dec '19
  • 1

    reply

  • 560

    views

  • 2

    users

You want something like this.

  void afisare_matrice(double A[][5], int n) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        printf("%5.1f", A[i][j]);
      }
      printf("\n");
    }
  }

Note the argument A should match the dimensions of the array you’re passing in, and n should be set to the size. Remember that for an array of dimension n, the indices go from 0 to n-1, not from 1 to n.