PDA

View Full Version : printing 9x9 array in C


rure
11-09-2007, 10:54 PM
I want to print out a 9x9 array in C in the following manner:

382 | 916 | 754
146 | 578 | 239
579 | 423 | 168
---------------
823 | 741 | 695
967 | 852 | 413
415 | 369 | 827
---------------
254 | 697 | 381
731 | 285 | 946
698 | 134 | 572

How would I do this?

BarrMan
11-09-2007, 11:23 PM
What you're trying to do is not 9x9. It's 3x9.

Try:
int arr[3][9];
arr[0][0] = 382;
arr[0][1] = 916;
arr[0][2] = 754;

arr[1][0] = 146;
arr[1][1] = 578;
arr[1][2] = 239;

//etc...

rure
11-09-2007, 11:57 PM
The numbers could be anything though, that was just an example.

BarrMan
11-10-2007, 12:42 AM
The numbers could be anything though, that was just an example.

ahh I see. So was that what you needed or not?

rure
11-10-2007, 12:59 AM
What I want is printing out the solution to a sudoku puzzle. Would I still use 3x9 and printf.

Spookster
11-10-2007, 03:14 AM
I would imagine your professor wants you to solve this homework assignment on your own. These type of homework assignments are as much about solving the problem as they are about being able to write the code to go with it.

A problem like this you should write an algorithm and use pseudocode first to figure out how to solve the problem and worry about what actual code to write later.

Obviously for this problem you will need some kind of nested looping construct to print out the columns and rows.