3x3 array = 10 numbers
Posted
by
user1708505
on Stack Overflow
See other posts from Stack Overflow
or by user1708505
Published on 2012-09-29T15:31:52Z
Indexed on
2012/09/29
15:37 UTC
Read the original article
Hit count: 147
i have this code
#include <math.h>
#include <stdio.h>
const int n = 3;
const int s = 3;
int getm(int mat[n][s]);
int printm(int mat[n][s]);
int main()
{
int m[n][s];
getm(m);
printm(m);
return 0;
}
int getm(int mat[n][s])
{
for(int x = 0;x < n;x++)
{
for (int y = 0;y<s;y++)
{
scanf("%i ", &mat[x][y]);
}
}
return 0;
}
int printm(int mat[n][s])
{
for(int x = 0;x<n;x++)
{
for(int y = 0;y<s;y++)
{
printf("%i ", mat[x][y]);
if(y==(s-1))
{
printf("\n");
}
}
}
}
which shoud ask for 9 numbers to make a 3x3 matrix array, but it actually asks for 10 numbers, printm is working well - printing only 9 numbers. Where is error?
© Stack Overflow or respective owner