I wrote this piece of code to find the GCD of any two numbers, and as I am working with multiple test cases, I used a 2D array with each testcase as a row and the first two elements in each row to store the numbers. FOr example, a[0][0] stores the first number of the first test case.
It works well up to user input, but the part which calculates the gcd, I'm getting a runtime error. I checked to see if I was trying to access an undefined location in the array, but with no luck.
const int testCase;
scanf("%d", &testCase);
int a[testCase][3], i, j, k;
for(k = 0; k < testCase; k++){
scanf("%d %d", &a[k][0], &a[k][1]);
}
// problem occurs after this
for(j = 0; j < testCase; j++){
for(i = 0; i <= a[j][0] && i <= a[j][1]; i++){
if(a[j][0] % i == 0 && a[j][1] % i == 0){
a[j][2] = i;
}
}
printf("%d\n", a[j][2]);