I need to store random numbers between 500 and 600 to an array using a pointer and then print out those numbers. I get a segmentation error…core dump, I don’t really understand what that means. The error happens after the printf statement (“%15d\n”, aPtr[i]);
int main(){
int size;
int j, i;
int temp;
int sum = 0;
printf("Enter size of array");
scanf("%d", &size);
int array[size];
int *aPtr = malloc(sizeof(int) * size);
for (i = 0; i <= size; i++){
srand(time(NULL));
aPtr[i] = rand() % 500 + 100;
printf("%15d\n", aPtr[i]);
you need to call srand ( which initializes the random number generator ) only once. Move it out of the for. And if you want random numbers between 500 and 600, you need to generate them between 0 and and 100 ( rand() % 101) and then add 500.