dimanche 27 mars 2016

C using random crashes my program

I'm new to C and trying to make a program that makes three 4x4 arrays and prints them to screen. My code shows no errors or warnings but crashes when ran. Debugging shows it's segmentation fault. What might be wrong?

I'm using Dev C++

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int i, j, k, l,r,r1,r2;
int a[4][4];
int b[4][4];
int c[4][4];
srand(time(NULL));

for (i=0;i<4;i++)
{
    for (j=0;i<4;j++)
    {

        r=rand() % 101;
            r1=rand() % 101;
                r2=rand() % 101;
        a[i][j]=r;
        b[i][j]=r1;
        c[i][j]=r2;

    }
}


for(k=0;k<4;k++)
{
    for (l=0;l<5;l++)
    {
        printf("\na:%d",a[k][l]);
            printf("\nb:%d",b[k][l]);
                printf("\nc:%d",c[k][l]);
    }
    }
}




Aucun commentaire:

Enregistrer un commentaire