Matrix with very large rows and columns in C

0

Good, I have a problem with a program where I have a matrix [N] [N] where N is 9000 but when I run the program I peta.

The question is this: The values of M (square matrix of size NxN, being N = 9000) not null will be generated pseudo-randomly and will be comprised between 0

Code:

#include <stdio.h>
#include <stdlib.h>
#define N 9000

int main()
{
    int **matriz;
    int i,j;
    // Reserva de Memoria
    matriz = (int **)malloc(N*sizeof(int*));
    for (i=0;i<=N;i++)
        matriz[i] = (int*)malloc(N*sizeof(int));

    rellenarMatriz(matriz);
    //imprimir(matriz);

    system("pause");
    return 0;
}

void rellenarMatriz(int **matriz[][N])
{
    int i,j;

    srand(time(NULL));

    for(i=0;i<N;i++){
        for(j=0;j<N;j++){
            if(i==j)
            {
                matriz[i][j] = 0;
            }
            else{
                matriz[i][j] = rand()%10;
            }
        }
    }
}

The error is as follows

    
asked by 21.09.2017 в 19:57
source

1 answer

0

I do not know why you say peta ; once the errors that prevent you from compiling have been fixed, it works:

You are missing this:

#include<time.h>

Change the types in your function rellenarMatriz( )

void rellenarMatriz( int ** );

Add, before the main , the prototype of the previous function.

With that, compile; although still giving a notice :

  

warning: unused variable 'j'

Now, if we execute it ... it works. And, at first glance, it seems that it does what it is supposed to do.

    
answered by 21.09.2017 в 20:12