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][1]=1; x[1][2]=2; x[2][1]=3; x[2][2]=4; x[3][1]=5; x[3][2]=6; y[1][1]=10; y[1][2]=20; y[1][3]=30; y[2][1]=40; y[2][2]=50; y[2][3]=60; z[1][1]=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][1]=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][1]=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