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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:24:58+00:00 2026-05-15T15:24:58+00:00

This program adds two matrices but it’s giving too many errors and I can’t

  • 0

This program adds two matrices but it’s giving too many errors and I can’t solve them.

Errors:

ARRAY BOUNDS MISSING

and

EXPRESSION SYNTAX

Any ideas?

#include<stdio.h>
#include<conio.h>

#define ROW=3
#define COL=3

int result[][COL];
void input(int arr[][COL]);
void add(int mat1[][COL],mat2[][COL]);
void print(int result[][COL]);

void main(void)
{
    int mat1[ROW][COL],mat2[ROW][COL];
    input(mat1);
    input(mat2);
    add(mat1,mat2);
    print(result);
    getch();
}

void input(int arr[][COL]);
{
    for(int i=0;i<row;i++)
        for(int j=0;j<col;j++)
        {
            printf("Enter element");
            scanf("%d",&arr[i][j]);
        }
}

void add(int mat1[][COL],int mat2[][COL])
{
    for(int i=0;i<row;i++)
        for(int j=0;j<col;j++)
        {
            result[i][j]=mat1[i][j]+mat2[i][j];
        }
}

void print(int result[][COL])
{
    for(int i=0;i<row;i++)
        for(int j=0;j<col;j++)
            printf("%d",result[i][j]);
}
  • 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-15T15:24:59+00:00Added an answer on May 15, 2026 at 3:24 pm

    That’s not a bad first attempt. At least you tried before you asked for help, which is more than some do here. You have the following problems:

    • Your defines are of the wrong format.
    • You use non-standard stuff (conio).
    • You use lowercase row and col for the constants.
    • Your input function has an extraneous semi-colon.
    • You don’t define result correctly.
    • The main function should always return an int.

    In more detail:

    (1) Your defines are of the wrong format.

    You don’t use = in defines since they’re supposed to be relatively simple text substitutions. So the line #define ROW=3 is not want you want since that’s basically trying to define the symbol ROW=3 to have an empty value.

    To get a symbol ROW with a value 3, you need to use #define ROW 3.

    Of course, in more modern code you would use static const int ROW = 3; since that would give you a first-class compiler symbol rather than just a text substitution. There really isn’t any need to use pre-processor definitions for constants (use const) or functions (use inline) nowadays.

    (2) You use non-standard stuff (conio).

    ISO C (the standard) does not include a conio.h header file. I understand that you’re using it so that you can use the getch function but ISO C provides a perfectly adequate getchar function which serves the same purpose here.

    It’s okay to use extensions to the language, just be aware that they generally make your code less portable.

    (3) You use lowercase row and col for the constants.

    Since you’ve used uppercase ROW and COL for your row and column constants, you should use uppercase in your for statements. C is a case-sensitive language and using row and col will cause the compiler to complain that they don’t exist.

    (4) Your input function has an extraneous semi-colon.

    This is just a misplaced ; in the first line of that function, at the end of the line containing the function devclaration.

    (5) You don’t define result correctly.

    The result variable should have a definite size. The definition int result[][10]; is what’s known as an incomplete type since the size cannot be known.

    (6) The main function should always return an int.

    There are two standard forms of the main function in C. Those are:

    int main(void);
    int main (int c, char *v[]);
    

    Others are allowed to be provided by the implementation but, if you want code that will run anywhere, you should limit yourself to one of those.


    This gets rid of all your syntax errors, now you can work on making the interface less ugly 🙂

    #include<stdio.h>
    
    #define ROW 3
    #define COL 3
    
    int result[ROW][COL];
    void input(int arr[][COL]);
    void add(int mat1[][COL],int mat2[][COL]);
    void print(int result[][COL]);
    
    int main(void)
    {
        int mat1[ROW][COL],mat2[ROW][COL];
        input(mat1);
        input(mat2);
        add(mat1,mat2);
        print(result);
        getchar();
        return 0;
    }
    void input(int arr[][COL])
    {
        for(int i=0;i<ROW;i++)
            for(int j=0;j<COL;j++)
            {
                printf("Enter element");
                scanf("%d",&arr[i][j]);
            }
    }
    void add(int mat1[][COL],int mat2[][COL])
    {
        for(int i=0;i<ROW;i++)
            for(int j=0;j<COL;j++)
                result[i][j]=mat1[i][j]+mat2[i][j];
    }
    void print(int result[][COL])
    {
        for(int i=0;i<ROW;i++)
            for(int j=0;j<COL;j++)
                printf("%d",result[i][j]);
    }
    

    Some suggestions for making it nicer:

    • Make it more obvious which value you’re entering by showing the matrix number and co-ordinates.
    • Make it print spaces between the output numbers.
    • Make it print newlines between the output lines.
    • Make it print the numbers fixed width (to line up nicely).
    • Comment your code (I can’t stress this enough).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Better to be putting your resources in a using( )… May 15, 2026 at 7:19 pm
  • Editorial Team
    Editorial Team added an answer First of all, the syntax for superators is superator ":="… May 15, 2026 at 7:19 pm
  • Editorial Team
    Editorial Team added an answer This was because 4.0 is using the modern runtime even… May 15, 2026 at 7: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.