# Thread: Help with matrix this question

1. ## Help with matrix this question

Hi guys, I really need your help for solving this problematic quiz the case is I need to make my own customized matrix but I'm stuck and here is what is have coded, this is my attachment :

prob-42.pdf
Code:
```#include <stdio.h>

int main(){
int m, n;
scanf("%d %d",&m,&n);
char matrix [30] [30];

for(int i=0;i<m;i++)
for (int j=0;j<n;n++)
scanf("%s",&matrix[i][j]);
printf("Your matrix result\n");
for(int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
printf("%c", matrix[i][j]);
printf("\n");
}
}```
Please help !

2. You have a bug on this line as you probably wanted to increment j, not n:
Code:
`for (int j=0;j<n;n++)`
You have a bug on this line as matrix[i][j] is a char, not a string (or more accurately, an array of char used to store a string):
Code:
`scanf("%s",&matrix[i][j]);`
From your printf call later, you probably wanted to use %c rather than %s.

3. It looks like you didn't learn anything from your previous homework.

"The first line will be an integer T, denoting the number of test cases".

So what does your first line looking like this supposed to do?
> scanf("%d %d",&m,&n);

It's like you write the first thing that comes into your head, discover it doesn't work and come running to the forum for an answer on a plate.

READ the question, break the problem down into simple single steps and build the program up one task at a time.

Your first scanf should be a single %d reading into a variable called numTestCases (like I showed you here)

4. I'm sorry @Salem. I need help because im a newbie to c programming i ussualy works with HTML, css and javascript.
I have an another question :

Code:
```#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main(){
int A[1000000000],B[1000000000];
int E,D;
int i,j,c;
int CaseNum,jawaban,answer;

scanf("%d",&CaseNum);
for(int i=0;i<=CaseNum;i++)
{
scanf("%d", &c);
for(int j=0;j<c;j++)
{
jawaban = 0;
for(j=0;j<c;j++)scanf("%lld", &A[j]);
for(j=0;j<c;j++)scanf("%lld", &B[j]);

for(int j=0;j<c;j++) answer[j]=A[j]*B[j];
}
for(j=0;j<c;j++) jawaban = jawaban;
printf("Case #%d: %lld\n",i,j);
}
return 0;
}```
I have a problem with the output that says :

and the program complains about invalid int[int] for array subscription that refers to this line of code :
Code:
`for(int j=0;j<c;j++) answer[j]=A[j]*B[j];`
can you solve it ?

5. Everytime you declare int j it's a new j, which you do three times (i.e. either one or two too many -- you can keep either the main one at the top or the two separate ones in the loops).

You didn't declare answer to be an array, so you can't use it as such.

6. > int A[1000000000],B[1000000000];
You've just used 8GB of stack space!

Start with something comfortable to work with, like 10.

> scanf("%d",&CaseNum);
> for(int i=0;i<=CaseNum;i++)
So if CaseNum is 1, how many times does this loop run?

> for(j=0;j<c;j++)scanf("%lld", &A[j]);
lld isn't for integers, it's for long long int's.

> I need help because im a newbie to c programming i ussualy works with HTML, css and javascript.
So?
The same process you follow for creating things in those things (breaking things down, step-wise refinement, debugging and testing) still apply.

Just stop lunging for the solution in one step and proceed slowly. You're just frustrating yourself with serial failure every time you do.
For you, this means you add ONE line at a time, press compile and make sure it works.

Popular pages Recent additions