title: Segmentation fault when the program tries write out the results
body: <p>Greeting,</p>
  
  <p>Somebody can find, why write out these program segmenation fault, when I take in the all inputs?
  I don't find where is the problem, or where should be modify my code</p>
  
  <p>And I would like to get the results?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  #include &lt;stdlib.h&gt;
  
  
  void inMatrix(int n, double **matrix)
  {
      int j, i;
      for (i = 0; i &lt; n; i++)
      {
          for (j= 0; j &lt; n; j++)
          {
              scanf("%lf", &amp;matrix[i][j]);
          }
      }
  }
  
  void inVector(double *vektor, int n)
  {
      int k;
      for (k = 0; k &lt; n; k++)
      {
          scanf("%lf", &amp;vektor[k]);
      }
  }
  
  void outVector(double *vektor, int n)
  {
      int k;
      for (k = 0; k &lt; n; k++)
      {
          printf("%.8lf ", vektor[k]);
      }
  }
  
  void lup(int n, double **A, double **b, int v)
  {
      int *Permutation = (int*)malloc(sizeof(int)*n);
      int i,j;
      int k;
      double *max = (double*) malloc (sizeof(double)*n);
      int m=0, p=0;
      int tmp=0, tmp2=0;
      int t=0, isSingular=0;
      double largestElement=0.0;
      double *helpVector = (double*) malloc (sizeof(double)*n);
      double *helpVectorA = (double*) malloc (sizeof(double)*n);
      double *helpVectorB = (double*) malloc (sizeof(double)*n);
  
  
  //    for(i=0;i&lt;n;i++)
  //    {
  //        for(j=0;j&lt;n;j++)
  //        {
  //            A[i][j]=D[i][j];
  //        }
  //    }
  
      for(i=0; i&lt;n; i++)
          Permutation[i]=i;
  
      for(m=0; m&lt;n-1; m++)
      {
          for(i=m; i&lt;n; i++)
          {
              max[i]=fabs(A[i][m]);
          }
          for(i=m; i&lt;n; i++)
          {
              if(max[i]&gt;largestElement)
              {
                  largestElement=max[i];
                  p=i;
              }
          }
          for(i=0; i&lt;n; i++)
          {
              helpVectorA[i]=A[m][i];
              helpVectorB[i]=A[p][i];
          }
          for(i=0; i&lt;n; i++)
          {
              A[m][i]=helpVectorB[i];
              A[p][i]=helpVectorA[i];
          }
          tmp=Permutation[m];
          tmp2=Permutation[p];
          Permutation[m]=tmp2;
          Permutation[p]=tmp;
          if(fabs(A[m][m])&gt;0.00000000000000001)
          {
              for(i=m+1; i&lt;n; i++)
              {
                  A[i][m]=A[i][m]/A[m][m];
                  for(j=m+1; j&lt;n; j++)
                  {
                      A[i][j]=A[i][j]-A[i][m]*A[m][j];
                  }
              }
          }
          if(fabs(A[m][m])&lt;0.00000000001)
          {
              printf("szingularis\n");
              isSingular=1;
              break;
          }
          for(i=0; i&lt;n; i++) max[i]=-1;
          largestElement=0.0;
          p=m+1;
      }
  
      if(isSingular==0)
      {
          if(fabs(A[n-1][n-1])&lt;0.00000000001)
          {
              printf("szingularis\n");
              isSingular=1;
          }
      }
      if(isSingular==0)
      {
          for(k=0; k&lt;v;k++)
          {
               for(i=0; i&lt;n; i++)
          {
              t=Permutation[i];
              helpVector[i]=b[k][t];
          }
          for(i=0; i&lt;n; i++)
          {
              b[i][k]=helpVector[i];
          }
  
          for(i=1; i&lt;n; i++)
          {
              for(j=0; j&lt;i; j++)
              {
                  b[k][i]-=A[i][j]*b[k][j];
              }
          }
          for(i=n-1; i&gt;=0; i--)
          {
              for(j=i+1; j&lt;n; j++)
              {
                  b[k][i]-=A[i][j]*b[k][j];
              }
              b[k][i]=b[k][i]/A[i][i];
          }
      }
      for(i=0; i&lt;n; i++)
      {
          printf("%.8lf ", b[k][i]);
      }
      printf("\n");
  
   }
  
  }
  
  int main()
      {
          int k, v,n;
          int j;
          double **A;
          double **C;
  
          // read dimension of matrix and value
          scanf("%d", &amp;n);
          //matrix
          A = (double **) calloc(n, sizeof ( double*));
          // matrix to store the vectors
          C = (double **) calloc(n, sizeof(double *));
  
          while(n!=0)
          {
          for (k = 0; k &lt; n; k++)
          {
              A[k] = (double *) calloc(n, sizeof ( double));
          }
              inMatrix(n, A);
  
              scanf("%d", &amp;v);
              for(k=0;k&lt;v;k++)
              {
                  C[k] = (double *) calloc(n, sizeof ( double));
              }
  
              for(k=0; k&lt;v;k++)
              {
                  for(j=0;j&lt;n;j++)
                  {
                      scanf("%lf", &amp;C[k][j]);
                  }
              }
              //print out result
              for(k=0;k&lt;v;k++)
              {
                  for(j=0;j&lt;v;j++)
                  {
                      lup(n,A,C,v);
                  }
              }
  
          }
      return 0;
  }
  </code></pre>