446,389 Members | 1,881 Online Need help? Post your question and get tips & solutions from a community of 446,389 IT Pros & Developers. It's quick & easy.

# printing

 P: n/a Hello Everybody, Basically C program prints the array elements in a column however I would like to print them in a matrix shape. For example see the following code which multiplies two matrices. #include #include #include #define N1 4 #define N2 4 #define M 3 int x[N1][M],y[M][N2],z[N1][N2]; int n1,n2,m; int main(void) { x=1; x=2; x=3; x=4; x=5; x=6; y=10; y=20; y=30; y=40; y=50; y=60; z=0; for (n1=1;n1
5 Replies

 P: n/a c language wrote: (OP wants output to look like a matrix) int x[N1][M],y[M][N2],z[N1][N2]; int n1,n2,m; int main(void) { x=1; Why are you indexing your arrays beginning at 1? Your code is correct, but you're wasting several elements at index 0, and it's less readable. for (n1=1;n1

 P: n/a c language schreef: How I can have the output in a 3*3 matrix? Use putchar('\n') in strategic places instead of in the prntf statement. Jun 14 '06 #3

 P: n/a Hi again, Thank you very much for your answers. I could use the Christopher's suggestions to fix the problem however there is one more thing. When I am asking the program to print on the screen, it works fine but when I try to have the results in an output file, everything is mixed up. Any suggestions about this problem? Thanks, MJ Christopher Benson-Manica wrote: c language wrote: (OP wants output to look like a matrix) int x[N1][M],y[M][N2],z[N1][N2]; int n1,n2,m; int main(void) { x=1; Why are you indexing your arrays beginning at 1? Your code is correct, but you're wasting several elements at index 0, and it's less readable. for (n1=1;n1 