Learn how to use a debugger.
Code:
$ gcc -g foo.c -lm
$ ./a.out
1
3
1 2 3
4 5 6
7 8 9
Segmentation fault
$ gdb ./a.out
GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/sc/Documents/a.out...done.
(gdb) run
Starting program: /home/sc/Documents/a.out
1
3
1 2 3
4 5 6
7 8 9
Program received signal SIGSEGV, Segmentation fault.
0x0000000000400831 in main () at foo.c:34
34 z=z+a[i][j];
(gdb) print z
$1 = -725259189
(gdb) print i
$2 = 110
(gdb) print j
$3 = 0
(gdb)
Mmm, i = 110
That doesn't look like a valid subscript.