a is a 3-by-3 matrix, but you try to index it with r1 and r2, which are two integers that have been directly assigned the return value of rand(). rand() returns a value between between 0 and RAND_MAX. RAND_MAX is usually around 32768.
In short, the program is crashing because you're reading way outside the bounds of an array.