Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6708139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:43:24+00:00 2026-05-26T07:43:24+00:00

Greeting, Somebody can find, why write out these program segmenation fault, when I take

  • 0

Greeting,

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

And I would like to get the results?

#include <stdio.h>
#include <math.h>
#include <stdlib.h>


void inMatrix(int n, double **matrix)
{
    int j, i;
    for (i = 0; i < n; i++)
    {
        for (j= 0; j < n; j++)
        {
            scanf("%lf", &matrix[i][j]);
        }
    }
}

void inVector(double *vektor, int n)
{
    int k;
    for (k = 0; k < n; k++)
    {
        scanf("%lf", &vektor[k]);
    }
}

void outVector(double *vektor, int n)
{
    int k;
    for (k = 0; k < 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<n;i++)
//    {
//        for(j=0;j<n;j++)
//        {
//            A[i][j]=D[i][j];
//        }
//    }

    for(i=0; i<n; i++)
        Permutation[i]=i;

    for(m=0; m<n-1; m++)
    {
        for(i=m; i<n; i++)
        {
            max[i]=fabs(A[i][m]);
        }
        for(i=m; i<n; i++)
        {
            if(max[i]>largestElement)
            {
                largestElement=max[i];
                p=i;
            }
        }
        for(i=0; i<n; i++)
        {
            helpVectorA[i]=A[m][i];
            helpVectorB[i]=A[p][i];
        }
        for(i=0; i<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])>0.00000000000000001)
        {
            for(i=m+1; i<n; i++)
            {
                A[i][m]=A[i][m]/A[m][m];
                for(j=m+1; j<n; j++)
                {
                    A[i][j]=A[i][j]-A[i][m]*A[m][j];
                }
            }
        }
        if(fabs(A[m][m])<0.00000000001)
        {
            printf("szingularis\n");
            isSingular=1;
            break;
        }
        for(i=0; i<n; i++) max[i]=-1;
        largestElement=0.0;
        p=m+1;
    }

    if(isSingular==0)
    {
        if(fabs(A[n-1][n-1])<0.00000000001)
        {
            printf("szingularis\n");
            isSingular=1;
        }
    }
    if(isSingular==0)
    {
        for(k=0; k<v;k++)
        {
             for(i=0; i<n; i++)
        {
            t=Permutation[i];
            helpVector[i]=b[k][t];
        }
        for(i=0; i<n; i++)
        {
            b[i][k]=helpVector[i];
        }

        for(i=1; i<n; i++)
        {
            for(j=0; j<i; j++)
            {
                b[k][i]-=A[i][j]*b[k][j];
            }
        }
        for(i=n-1; i>=0; i--)
        {
            for(j=i+1; j<n; j++)
            {
                b[k][i]-=A[i][j]*b[k][j];
            }
            b[k][i]=b[k][i]/A[i][i];
        }
    }
    for(i=0; i<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", &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 < n; k++)
        {
            A[k] = (double *) calloc(n, sizeof ( double));
        }
            inMatrix(n, A);

            scanf("%d", &v);
            for(k=0;k<v;k++)
            {
                C[k] = (double *) calloc(n, sizeof ( double));
            }

            for(k=0; k<v;k++)
            {
                for(j=0;j<n;j++)
                {
                    scanf("%lf", &C[k][j]);
                }
            }
            //print out result
            for(k=0;k<v;k++)
            {
                for(j=0;j<v;j++)
                {
                    lup(n,A,C,v);
                }
            }

        }
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:43:24+00:00Added an answer on May 26, 2026 at 7:43 am

    In function lup, at line 157 (in the second “if(isSingular==0)” block) you wrote

    printf("%.8lf ", b[k][i]);
    

    this line is written in a for-loop iterating on i, while k has a leftover value from the last loop. The break condition of that loop was that k = v (the size of C, A.K.A “b” from the line of code above).

    So, basically, you wrote:

    printf("%.8lf", b[MaxIndexOfB+1][i];
    

    And that’s probably the stinker you’re looking for.

    Two notes. First, I’ve been .Net man for too long, so I might be missing something completely trivial here, In that case, sorry.
    Second, when you want people to read your code (like when posting it for help), it’s imperative to use more meaningful names, or something to improve code readability, but if you’re not going to do this, at least avoid confusing stuff like passing variable named “C” into parameter named “b” if it’s avoidable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings guys, hopefully somebody has fresher eyes and can help me pinpoint the problem
greeting all i am working on school project and i have a problem with
Groovy has a concept of GStrings. I can write code like this: def greeting
Greetings all... I am hoping somebody can shed me some lights about the issue
Greetings! I am trying to check directory write-permissions from within a Windows MFC/ATL program
Greeting all. I have a SQL Server 2008 Express database with a table called
Greeting all... i have two table and their structure is identical... Table logDetail Date
Greeting all, iptables -L gives the following output [root@ibmd ~]# iptables -L Chain INPUT
Greeting! I've done a project that can send GPS Coordinates to mobile number Automatically,
i saw this code somewhere switch(greet){ case HELLO: System.out.println(Formal Greeting); break; case HI: System.out.println(Friendly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.