print results in a matrix-like style with system calls
<p>I need to print out the result of a matrix multiplication using only system calls. I get the proper results but not in the appropriate format. I get 1000x1000 rows but I'd need 1000 colums x 1000 rows. Any idea how to do it?</p>

<p>This is the code I've written:     </p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;unistd.h&gt;

#define N 1000

// Matrix 
long long int A[N][N],B[N][N],R[N][N];

int main(int argc, char *argv[])
{
    int x,y,z;
    char str[100];

    /* Matrix inicialization */
    for(y=0;y&lt;N;y++) 
        for(x=0;x&lt;N;x++)
        {
            A[y][x]=x;
            B[y][x]=y;
            R[y][x]=0;  
        }

    /* Matrix multiplication */
    for(y=0;y&lt;N;y++)
        for(z=0;z&lt;N;z++) 
            for(x=0;x&lt;N;x++) 
            {
                R[y][x]+= A[y][z] * B[z][x];    
            }

   /* Printing result */
    for(y=0;y&lt;N;y++)
        for(x=0;x&lt;N;x++)
        {
            sprintf(str, "%lli\n", R[y][x]);
            write(1, str, strlen(str));
        }

    exit(0);
}
</code></pre>

<p>Thanks in advance!</p>