Rick asked:
> was there a less torturous way of doing this

You've used a one-dimensional array. Why not use a 
two-dimensional array? Because 2-D arrays in C have to be 
rectangular, you'll need to include a code for the 
non-existent numbers (i.e. padding); perhaps 0 or -1?

An element of a 2-D array is accessed as table[i][j], where 
i is the row index and j the column index.

An alternative is to use an array of pointers to arrays of 
ints; the int arrays can be of different lengths. (This is 
the standard approach for arrays of strings, using chars 
instead of ints of course.) But then you need to do pointer 
arithmetic; the a[i][j] notation won't work.

> (ignoring the obvious flaw
> of having to recompile for every new question)?

Put the table in a text file and read it in at run time. 
Unless the table is always the same size, you'll have to 
allocate memory for it dynamically (malloc).

Or you could use a database.  ;-)

David

Reply via email to