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 7848737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:18:38+00:00 2026-06-02T18:18:38+00:00

This code is asking the user to fill out to matrix and then it

  • 0

This code is asking the user to fill out to matrix and then it calls a void function to add them together. I have a http://www.ideone.com
I cannot change much of the code also. It is requeired to have all those define statements and a void function.

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

#define NCOL1 2
#define NCOL2 2
#define NROW1 2
#define NROW2 2
#define NCOL3 2
#define NROW3 2

int main (void)
{
    //Initiate variables
    double a, b;
    int    i, j;
    void   addarray(double a, double b);
    double ans;
    double arr1[NCOL1][NROW1], arr2[NCOL2][NROW1];

    //Ask user to enter numbers for the first matrix
    printf("Please enter numbers for Matrix 1 :\n ");
    for (i = 0; i < NCOL1; i++) {
        for (j = 0; j < NROW1; j++) {
            scanf("%lf", &arr1[i][j]);
        }
    }

    //Ask user to enter numbers for the second matrix
    printf("Please enter numbers for Matrix 2 :\n ");
    for (i = 0; i < NCOL2; i++) {
        for (j = 0; j < NROW2; j++) {
            scanf("%lf", &arr2[i][j]);
        }
    }

    //Iterate through void function and print out result
    for (i = 0; i < NCOL3; i++) {
        for (j = 0; j < NROW3; j++) {
            addarray(arr1[i][j], arr2[i][j]);
            printf("%lf", ans);
        }
    }
    return 0;
}

void addarray (double a, double b)
{
    int i,j;
    double arrsum[NCOL3][NROW3];
    for (i = 0; i < NCOL3; i++) {
        for (j = 0; j < NROW3; j++) {
            arrsum[i][j] = a + b;
        }
    }
}
  • 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-06-02T18:18:41+00:00Added an answer on June 2, 2026 at 6:18 pm

    EDIT: A better solution to the problem is:

    #include<stdio.h>
    #include<math.h>
    #define NCOL1 2
    #define NCOL2 2
    #define NROW1 2
    #define NROW2 2
    #define NCOL3 2
    #define NROW3 2
    
    
    void addarray(double a[NROW1][NCOL1], double b[NROW1][NCOL1], double (*c)[NCOL1]);
    
    
    int main(void)
            {
      //Initiate variables
      double a,b;
      int i,j;
      double ans;
      double arr1[NCOL1][NROW1], arr2[NCOL2][NROW1];
      double arrsum[NCOL1][NROW1];
    
      //Ask user to enter numbers for the first matrix
      printf("Please enter numbers for Matrix 1 :\n ");
        for(i=0;i<NCOL1;i++){
           for(j=0;j<NROW1;j++){
             scanf("%lf",&arr1[i][j]);
           }
        }
      //Ask user to enter numbers for the second matrix
        printf("Please enter numbers for Matrix 2 :\n ");
        for(i=0;i<NCOL2;i++){
          for(j=0;j<NROW2;j++){
            scanf("%lf",&arr2[i][j]);
          }
        }
    
    
        addarray( arr1, arr2, &arrsum[0] );
    
        printf("Output of added arrays\n");
        for(i=0;i<NCOL3;i++){
                for(j=0;j<NROW3;j++){
                        printf("%lf ", arrsum[i][j]);
                }
            printf("\n");
        }
    
    
        return 0;
    }
    
    void addarray(double a[NROW1][NCOL1], double b[NROW1][NCOL1], double (*c)[NCOL1])
    {
        int i,j;
    
        for(i=0;i<NCOL3;i++)
        {
            for(j=0;j<NROW3;j++)
            {
                c[i][j] = a[i][j] + b[i][j];
            }
        }
    }
    

    But, with minimal changes the following will also work.

    It looks like addarray() is putting it’s results into a local matrix called arrsum[][]. For this program to work you will most likely want to make arrsum[][] available to the rest of the program ( although a global array is not a great idea ).

    Without testing or compiling the code you should make these changes at a minimum:

    1- Remove double arrsum[NCOL3][NROW3]; from addarray()

    void addarray(double a,double b)
    {
            int i,j;
    
            for(i=0;i<NCOL3;i++){
                    for(j=0;j<NROW3;j++){
                            arrsum[i][j]=a+b;
                    }
    }
    

    2- Make arrsum[][] global

    #include<stdio.h>
    #include<math.h>
    #define NCOL1 2
    #define NCOL2 2
    #define NROW1 2
    #define NROW2 2
    #define NCOL3 2
    #define NROW3 2
    
    /****  add declaration of arrsum[][] here ****/
    double arrsum[NCOL3][NROW3];
    

    I’ve gone and rewritten parts of the program, compiled and tested it. The new code is below.

    #include<stdio.h>
    #include<math.h>
    #define NCOL1 2
    #define NCOL2 2
    #define NROW1 2
    #define NROW2 2
    #define NCOL3 2
    #define NROW3 2
    
    
    void addarray(double a,double b);
    
    
    double arrsum[NCOL3][NROW3];
    
    int main(void)
            {
      //Initiate variables
      double a,b;
      int i,j;
      double ans;
      double arr1[NCOL1][NROW1], arr2[NCOL2][NROW1];
      //Ask user to enter numbers for the first matrix
      printf("Please enter numbers for Matrix 1 :\n ");
        for(i=0;i<NCOL1;i++){
           for(j=0;j<NROW1;j++){
             scanf("%lf",&arr1[i][j]);
           }
        }
      //Ask user to enter numbers for the second matrix
        printf("Please enter numbers for Matrix 2 :\n ");
        for(i=0;i<NCOL2;i++){
          for(j=0;j<NROW2;j++){
            scanf("%lf",&arr2[i][j]);
          }
        }
        //Iterate through void function and print out result
        for(i=0;i<NCOL3;i++){
          for(j=0;j<NROW3;j++){
            addarray(arr1[i][j],arr2[i][j]);
    //        printf("%lf",ans);
          }
        }
    
        printf("Output of added arrays\n");
        for(i=0;i<NCOL3;i++){
                for(j=0;j<NROW3;j++){
                        printf("%lf ", arrsum[i][j]);
                }
            printf("\n");
        }
    
    
        return 0;
    }
    
    void addarray(double a,double b)
    {
            int i,j;
    
            for(i=0;i<NCOL3;i++){
                    for(j=0;j<NROW3;j++){
                            arrsum[i][j]=a+b;
                    }
            }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to make this piece of code loop asking for input from the user
When using this code (simplified for asking): var rows1 = (from t1 in db.TABLE1
This code gives me an empty result. I expect it to print out the
This code: $(#permalink a).click(function(id){ var id = this.getAttribute('href'); $(#newPostContent).load(id, function() { $(#removeTrigger).click(function() { $(#removeThis).hideToggle();
Newbie here. I have this code: while (v < 360) { v +=10; RunIt();
I have this program, which as you can see is pulling random pictures out
When a user clicks on Delete this post a modal pops up asking if
I have this code where I do this as soon as the map loads
I have written a piece of code in python, in which I am asking
I'm using python 2.6.6 and I can't solve my problem. I have this code:

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.