Re: print matrix

From: Arthur J. O'Dwyer (ajo_at_nospam.andrew.cmu.edu)
Date: 06/04/04


Date: Fri, 4 Jun 2004 16:14:10 -0400 (EDT)


On Fri, 4 Jun 2004, Ronen Kfir wrote:
>
> I need to take as an input matrix N*M from stdin & print it as a
> matrix shape, something like:

  First, pick one group and stick to it. Don't multi-post your
message to many different groups. If you *must* post to multiple
groups, then cross-post, like I did in this response (a response
written in response to your question in comp.lang.c, BTW).

  Secondly, no matter what language you're using, you need to
know *what* you're doing before worrying about the *how*. What
kind of input is the user going to be typing? Is he going to
enter

  1 2 3 4 5 6 7 8 9

and you're by magic going to print

  1 2 3
  4 5 6
  7 8 9

or is the user going to have to tell the program how many dimensions
the matrix has, and what size it is, like this?

  4 2
  1 2 3 4 5 6 7 8

and then you would print a 4-by-2 matrix

  1 2 3 4
  5 6 7 8

Maybe the user is going to enter his matrix himself, and use some
special code to indicate that he's done entering rows, like this:

  1 2 3 4 5
  6 7 8 9 10
  11 12 13 14 15
  done

In this last case, would you output

  1 2 3 4 5
  6 7 8 9 10
  11 12 13 14 15

or would your user rather see

   1 2 3 4 5
   6 7 8 9 10
  11 12 13 14 15

In the latter case, should the entries by justified toward the right,
the left, or centered: e.g.,

  1 2 3
  42 567 8
  17 42 725

Should the columns all be equally wide, e.g.

      1 2 65535
      3 4 5

or should they have variable width, e.g.

  1 2 65535
  3 4 5

If the latter, then would it be acceptable to overlap
columns on particularly odd inputs, e.g.

  1 2 1234567890 3 4
  2 456 89 10112 7

If not, then how many spaces between columns? Are hard
tabs okay? (Hint: no. ;) Answer these questions for
yourself, and *then* think about what algorithms you'll
need to implement.

  Once you know not only *what* you're doing, but also
*how* you'll do it (i.e., the algorithms involved), then
you'll finally be ready to start asking questions that
might be topical on comp.lang.c and alt.comp.lang.learn.c-c++.
We deal with the C *language* here, not algorithms; for
algorithm help, try comp.programming.

-Arthur



Relevant Pages

  • Re: print matrix
    ... groups, then cross-post, like I did in this response (a response ... Secondly, no matter what language you're using, you need to ... columns on particularly odd inputs, ... *how* you'll do it (i.e., the algorithms involved), then ...
    (alt.comp.lang.learn.c-cpp)
  • Re: A question for the implementers
    ... algorithms would never have been discovered if it had? ... the risk of complicating user's understanding of the language. ... that, in the extreme, an error-free language would be unusable. ... arg, then the error is caught when the function is invoked as in ...
    (comp.lang.apl)
  • Re: why learn C?
    ... i think programming is different from Software Engineering. ... then I can find other algorithms I have needed which are ... *not* part of which ever language you choose to select. ... and you will have done at least some algorithm development whether you ...
    (comp.lang.c)
  • Re: Java or C++?
    ... for the stuff we do, its the algorithms do tend to be complex, so I ... mostly because of the predictability of the language. ... where all the intervening steps are as light-weight as possible. ... developed hardware in VHDL. ...
    (comp.programming)
  • Re: Other than php/perl/lisp/c/c++/java, anybody have a favorite computer-programming language?
    ... Picking an element based on index makes sense for strings and other ... GCD and a few other algorithms depend on that and would ... on the basis of how well that language supports the functional and ... (data types part 1, mostly the types that can be used as literals ...
    (comp.programming)