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

  • SEARCH
  • Home
  • 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 639095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:48:15+00:00 2026-05-13T20:48:15+00:00

hey there, Im having problems displaying my results in this program but the program

  • 0

hey there, Im having problems displaying my results in this program but the program compiles. Any idea as to what is going wrong?. The purpose of the program is to take two, 2 by 2 matrixes and add them to create the matrix called result. but when it comes to displaying the values in each matrix (A,B and result) it hangs. why does at the search(A,0,0) call?

-thanks

#include <stdio.h>

int gvalue;

struct Node {
    int row;
    int column;
    int value;
    Node *next;
};

void AddNode(Node *&listpointer,int r,int c,int v);
void getValue(Node *listpointer, int grow, int gcol);
void search(Node *listpointer, int srow, int scol);
void display(Node *listpointer,int drow,int dcol,int dvalue);
Node *A,*B,*result;

int main(){
    A = NULL;
    B = NULL;
    result = NULL;

    int row1p1,row1p2,row2p1,row2p2; //row 1 position 1 etc

    //matrix A values!
    printf("Enter the first row of values for matrix A: ");
    scanf("%d %d",&row1p1,&row1p2);
    printf("\nEnter the second row of values for matrix A: ");
    scanf("%d %d",&row2p1,&row2p2);

    AddNode(A,0,0,row1p1); //matrix created...
    AddNode(A,0,1,row1p2);
    AddNode(A,1,0,row2p1);
    AddNode(A,1,1,row2p2);

    //matrix B values!
    printf("\n\nEnter the first row of values for matrix B: ");
    scanf("%d %d",&row1p1,&row1p2);
    printf("\nEnter the second row of values for matrix B: ");
    scanf("%d %d",&row2p1,&row2p2);

    AddNode(B,0,0,row1p1); //matrix created...
    AddNode(B,0,1,row1p2);
    AddNode(B,1,0,row2p1);
    AddNode(B,1,1,row2p2);


    //next part...
    int a_row1p1,a_row1p2,a_row2p1,a_row2p2;
    int b_row1p1,b_row1p2,b_row2p1,b_row2p2;
    int sum;
    //-------------------------------------------------------------------------------|
    getValue(A,0,0);            //RESULT NODE for position 0,0
    a_row1p1=gvalue;
    getValue(B,0,0);
    b_row1p1=gvalue;

    sum=a_row1p1+b_row1p1;
    AddNode(result,0,0,sum);   

    getValue(A,0,1);                //RESULT NODE for position 0,1
    a_row1p2=gvalue;
    getValue(B,0,1);
    b_row1p2=gvalue;

    sum=a_row1p2+b_row1p2;
    AddNode(result,0,1,sum); 

    getValue(A,1,0);                //RESULT NODE for position 1,0
    a_row2p1=gvalue;
    getValue(B,1,0);
    b_row2p1=gvalue;

    sum=a_row2p1+b_row2p1;
    AddNode(result,1,0,sum); 

    getValue(A,1,1);                //RESULT NODE for position 1,1
    a_row2p2=gvalue;
    getValue(B,1,1);
    b_row2p2=gvalue;

    sum=a_row2p2+b_row2p2;
    AddNode(result,1,1,sum); 
    printf("success\n");
    //-------------------------------------------------------------------------------|
    search(A,0,0);
    printf("success\n"); //issue????
    search(A,0,1);
    search(A,1,0);
    search(A,1,1);


    search(B,0,0);
    search(B,0,1);
    search(B,1,0);
    search(B,1,1);

    search(result,0,0);
    search(result,0,1);
    search(result,1,0);
    search(result,1,1);



    return 0;
}

void AddNode(Node *&listpointer,int r,int c,int v){
    Node *temp;
    temp = new Node;
    temp->row = r;
    temp->column = c;
    temp->value = v;
    temp->next = listpointer;
    listpointer = temp;
}

void getValue(Node *listpointer, int grow, int gcol){
    Node *current;
    current = listpointer;
    while (current != NULL){
        if (current == NULL){break;}
        if ( (current->row == grow ) && (current->column == gcol) ){
            gvalue = current->value;
            break;
        }
        current = current->next;
    }
}

void search(Node *listpointer, int srow, int scol){
    Node *current;
    current = listpointer;
    while (current != NULL){
        if (current == NULL){break;
        }
        if ( (current->row == srow) && (current->column == scol) ){
            display(current,srow,scol,current->value); //call to display
        }
    }
}

void display(Node *listpointer,int drow,int dcol,int dvalue){
    if (listpointer == A){
        printf("\n\nMatrix A\n");
    }
    if (listpointer == B){
        printf("Matrix B\n");
    }
    if (listpointer == result){
        printf("Matrix Result\n");
    }
    //---------------------------------------------------------|
    if ( (drow == 0) && (dcol == 0) ){
        printf("%d ",dvalue);
    }
    if ( (drow == 0) && (dcol == 1) ){
        printf("%d\n",dvalue);
    }
    if ( (drow == 1) && (dcol == 0) ){
        printf("%d ",dvalue);
    }
    if ( (drow == 1) && (dcol == 0) ){
        printf("%d\n\n",dvalue);
    }

}
  • 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-13T20:48:15+00:00Added an answer on May 13, 2026 at 8:48 pm

    I’m assuming that this is homework. How is the loop going to end if current does not meet either of the two conditions you check. You need to set current to the next node of the list at some point.

     while (current != NULL){
            if (current == NULL){break;
            }
            if ( (current->row == srow) && (current->column == scol) ){
                display(current,srow,scol,current->value); //call to display
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 375k
  • Answers 375k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The reason it's not working is that in Javascript, this… May 14, 2026 at 8:20 pm
  • Editorial Team
    Editorial Team added an answer You should extend JDialog See the dialogs tutorial May 14, 2026 at 8:20 pm
  • Editorial Team
    Editorial Team added an answer As far as I'm concerned, access to any Google spreadsheet… May 14, 2026 at 8:19 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.