Having a problem with my code. I have made some research about the problem, but the solution I found seems not be solve my problem. Most of the solutions said that it is due to array out of index. Here is my code.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int myrandom(int min, int max){
return min + rand() / (RAND_MAX / (max - min + 1) + 1);
}
int main() {
clock_t begin = clock();
int T1[1000000];
int T2[1000000];
int T3[1000000];
for (int i = 0; i < 1000000; i++) {
T1[i] = myrandom(-10, 10);
T2[i] = myrandom(-10, 10);
T3[i] = T1[i]*T2[i];//<-- Getting Segmentation fault (core dumped) here
}
clock_t end = clock();
double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
printf("Program terminé en %f Secondes\n", time_spent);
}
malloc()and similar functions or use static variables.size_tfor array indexing and notint. Your code break whenINT_MAX<1000000(even when you would usesize_t).