1. ## matrix summation

anyone help me to correct the code ? where's the error ?

Code:
```// MATRIX SUMMATION

#include<stdio.h>

# define MAXROWS 20
# define MAXCOLS 30

void readinput (int a[][MAXCOLS], int nrows, int ncols );
void computesums (int a[][MAXCOLS], int b[][MAXCOLS], int c[][MAXCOLS], int nrows, int ncols);
void writeoutput ( int c[][MAXCOLS] , int nrows, int ncols);

void main()

{

int nrows, ncols;
int a[MAXROWS][MAXCOLS], int B[MAXROWS][MAXCOLS] , int C[MAXROWS][MAXCOLS] ;

printf("How many rows?");
scanf("%d", &nrows);
printf("How many columns?");
scanf("%d", &ncols);

printf("\n\nFirst matrix:\n");

printf("\n\nSecond matrix:\n");

computesums (a,b,c, nrows, ncols);
printf("\nSums of the elements:\n\n");
writeoutput(c, nrows, ncols);

}

void readinput( int a[][MAXCOLS], int m , int n)

{
int row,col ;
for(row=0;row<m; ++ row)

{
printf("\nEnter the data for row no. %d\n", row+1);

for(col=0;col<n;++col)

scanf("%d", &a[row][col]);

}

return;

}

void computesums( int a[][MAXCOLS] , int a[][MAXCOLS], int c[][MAXCOLS] , int m, int n)

{

int row, col;
for(row=0; row<m;++row)

for(col=0; col<n;++col)

c[row][col]=a[row][col]+b[row][col] ;

return;

}

void writeoutput( int c[][MAXCOLS], int m, int n)

{
int row, col;
for(row=0;row<m;++ row)

{

for(col=0; col<n;++col)

printf("%d", a[row][col]);
printf("\n");

}

return;

}```

2. The FIRST error is the part where you waste our time - since obviously you know the error in output - and decide not to state what that error is.

3. since obviously you know the error in output - and decide not to state what that error is.

4. Umm, I'm no expert, but I don't think there should be a space between # and define…

Oh, and Adak: OI, SHUT UP! What if (s)he ACTUALLY doesn't know? Ever thought of that?

EDIT: Also, what compiler are you using? Usually it tells you what the problem is.

5. Indeed I have thought about that. I also thought about advising you to refrain from telling others to shut up, mszegdy.

Of course chaklader knows more about the problem, since he/she must have tried to compile or link it, at least.

If you want help with a program, you need to share the relevant information you have.

6. I'm sorry. I just happen to become rudely hostile when one person treats another person's words that are, for all purposes, innocent and sincere, with extreme rudeness and hostility.

As such, I believe that if chaklader had enough information to know how to solve the problem, (s)he would not post a topic about it in the first place.

I have examined this code (granted, not extremely carefully) and have found nothing amiss. I will continue looking for errors. I think that #define thing might be the reason.

What does your compiler say? I would run it through mine, but I'm typing this on an iPhone.

Also, I would add two "if" flow controls (or possibly two "while" loops) to the main procedure that checks if the number of rows and columns given are below MAXCOLS and MAXROWS.

Oh, and in the very first part of main when you are declaring those variables, make "B" and "C" lowercase. They are referred to everywhere else as "b" and "c", and it's case-sensitive I believe.

7. Adak @ actually i thought its not necessary to share the compiler information .... however as you need that -

error C2065: 'b' : undeclared identifier
error C2065: 'c' : undeclared identifier
error C2086: 'a' : redefinition
error C2109: subscript requires array or pointer type
error C2109: subscript requires array or pointer type
error C2065: 'a' : undeclared identifier
error C2109: subscript requires array or pointer type
error C2109: subscript requires array or pointer type

8. mszegedy @ thanks for your care .

9. You're welcome.

Huh, "a" redefinition? Waitasec…

Uh, replace "a" in computesums with some other name. It's confusing the compiler and messing things up.

You might want to read the edit I made to my previous post. It's also messing your compiler up.

It should work now.

EDIT: Whoops, change "b" and "c" too. In computesums.

10. Originally Posted by mszegedy
I'm sorry. I just happen to become rudely hostile when one person treats another person's words that are, for all purposes, innocent and sincere, with extreme rudeness and hostility.

As such, I believe that if chaklader had enough information to know how to solve the problem, (s)he would not post a topic about it in the first place.

I'm not being "rude and hostile", I'm trying to help Chaklader, solve a problem - quickly and efficiently.

Would you prefer that I lie to Chaklader? I can't change the reality of the internet, this forum, or people in general. Truth is, they NEED to know the compiler or linker errors, if present, and they won't help posters who waste their time, nearly as much.

Shall I gift wrap that for you, or is plain truth, in plain text, sufficient?

In this function, the second parameter should be b, to match the function prototype.
Code:
`void computesums( int a[][MAXCOLS] , int a[][MAXCOLS],`
In writeoutput(), you are referring to the a[] array, and you didn't bring in the a[] array, as a parameter to the function.

In main(), B[] and C[], should be b[] and c[]. Everything is case sensitive in C.

You don't want the word "int" before each variable in a list:

int a[], b[][], c[][][], FILL IN THE SIZES, and then just one semi-colon on the end. Only one "int", though.

11. Yes, telling someone (s)he is "wasting our time" is a very quick and efficient way of solving a problem.

Perhaps (s)he doesn't know what his/her compiler is trying to tell him/her. It is very hard to understand compiler text if you don't think like a computer, or understand what "unsigned" means or what a "segmentation fault" is. Not that those appeared in the text. Worse, if your compiler isn't particularly verbose, you can end up with meaningless errors like SEGFAULT and such. And what the heck is that 2 supposed to mean before each line number? "2109" doesn't sound very much like a line number.

12. Wait, he's offline. I'd better go to sleep (it's 3:30 AM where I am).

13. Originally Posted by mszegedy
Yes, telling someone (s)he is "wasting our time" is a very quick and efficient way of solving a problem.

Perhaps (s)he doesn't know what his/her compiler is trying to tell him/her. It is very hard to understand compiler text if you don't think like a computer, or understand what "unsigned" means or what a "segmentation fault" is. Not that those appeared in the text. Worse, if your compiler isn't particularly verbose, you can end up with meaningless errors like SEGFAULT and such.
Three short words == quick!

I don't CARE what the poster understands - we'll help with that. I need to know WHAT the compiler or linker error content IS.

Those errors may be meaningless to you - but they are very meaningful to me (and others on this forum).

Why don't you kick back for a bit, and see how well this forum works?

Would you trust a doctor who didn't insist on knowing your symptoms when you get sick? I sure wouldn't.

We're not here to hold the poster's hands. We solve problems from posters who are willing to make a real effort, and are forthright with the info we need. And we do it for free.

Pretty neat, if you think about it.

14. mszegedy @ I really respect your care . Anyhow , please don't leave the forum .
Adak @ The program is working now and I understood you as well . thanks for your help.

15. @mszegedy My oh my aren't you the incarnation of forum ethics and dedication to helping others with your 8 posts, 5 of which are on this thread and make no attempt at solving the OP's problem.