matrix in C language
that's how i input:
int m,n;
int i,j;
scanf("%d%d",&n,&m);
int matrix[n][m];
for(i=0;i<n;i++){
for(j=0;j<m;j++){
scanf("%d",matrix[i]+j);
}
}
you need to put reference on matrix[i][j],
scanf("%d",&matrix[i][j]) ...This is how you input matrix of characters ->
char Matrix[1001][1001];
scanf("%d %d",&n, &m);
for ( int i = 0; i < n; i++)
{
scanf("%s",Matrix[i]);
}
it goes with it. For strings I'm allways doing without it, but its not a mistake cause its the same.
Ok.
You don't need to use '{' & '}' when you have only one statement in for, while, if...
Matrix of characters:
Matrix of integers:
It is the same, but code is better without it if you don't need it. :D
Matrix of characters:
char mat[10][10];
for ( int i=0;i<n;++i )
scanf("%s",mat[i]);
Matrix of integers:
int mat[10][10];
for ( int i=0;i<n;++i )
for ( int j=0;j<n;++j )
scanf("%d",&mat[i][j]);
It is the same, but code is better without it if you don't need it. :D
it's reading ...
you can read
and then go throw matrix and search for elements
or
when you are reading you need to put space before %c ...
you can read
for (int i = 0; i < n; i++)
scanf("%s",matrix[i]);
and then go throw matrix and search for elements
or
when you are reading you need to put space before %c ...
scanf("[space]!!!%c",&c);
//it need to look like
scanf(" %c",&c);
hmmm ... why in for j <= m ??? it should be j < m ...
and i thing u will get memory reference because u are looking in matrix[i-1][j] and what if it's i = 0 u will look in matrix[-1!!!][j] ...
and i thing u will get memory reference because u are looking in matrix[i-1][j] and what if it's i = 0 u will look in matrix[-1!!!][j] ...
what if it's i = n and you are looking for i+1 ...
n can be 1000 and you are looking for matrix[1001][j] and for j same ...
in init just do bool matrix[1005][1005] ...
and in begining set hole matrix to false ...
memset(matrix, 0, sizeof(matrix));
or with 2 for loops ... whatever you want ... and try again
n can be 1000 and you are looking for matrix[1001][j] and for j same ...
in init just do bool matrix[1005][1005] ...
and in begining set hole matrix to false ...
memset(matrix, 0, sizeof(matrix));
or with 2 for loops ... whatever you want ... and try again
got it thanks
np ... :D
you could use bool, no need for long ... but nevermind ...
you could use bool, no need for long ... but nevermind ...