mercredi 25 avril 2018

Array not being randomized as it should and values coming in negative

so I'm trying to store random numbers using the srand function to store values in a 2D Array using a loop. When I print out the array it has the same values everytime and the numbers are often in negative values which is strange and also they remain the same even if srand function is there.

#include <stdio.h>
#include <math.h>
#include <time.h>

#define NROW 13
#define NCOL 11


int main()

{

void disp_array(int a[NROW][NCOL]);

int ar[NROW][NCOL];
int i,j;




for (i=0;i<NROW;i++){

for(j=0;j<NCOL;j++){

    ar[NROW][NCOL]= (rand()%101);

    }

}

 disp_array(ar);

return 0;

}

void disp_array(int a[NROW][NCOL]){

int i;
int j;



for(i=0;i<7;i++){


for(j=0;j<5;j++){

printf("Value at row %d column %d is %d \n",i,j,a[i][j]);

        }
}



}

`




Aucun commentaire:

Enregistrer un commentaire