I'd like to see a matrix in C language, but how do I pre-assign values using the for
statement as a fixed value instead of substituting values with scanf
?
I would like the results to be as follows.
A=
1 2 3 4
5 6 7 8
9 10 11 12
You can loop from 1 to the size of the array and replace the number.
You may want to express the three rows and four columns in a two-dimensional array, and then set the values for the elements in order (using for-loop here).
const M=3;
constint N = 4;
int A[M][N];
for(intm=0;m<M;m++){
for(intn=0;n<N;n++){
A[m][n]=n+(N*m)+1;
}
}
printf("A=\n");
for(intm=0;m<M;m++){
printf("";
for(intn=0;n<N;n++){
printf("%d", A[m][n]);
}
printf("\n");
}
© 2024 OneMinuteCode. All rights reserved.