Re: Exercise from C++ How to program Cyber classroom 4th ed.

From: Dan Cernat (dcernat_at_excite.com)
Date: 01/07/04


Date: 7 Jan 2004 06:20:39 -0800


"John Carson" <donaldquixote@datafast.net.au> wrote in message news:<3ffbe237$1@usenet.per.paradox.net.au>...
> "Bruce Lee 646" <brucelee646@aol.com> wrote in message
> news:20040107051345.01665.00002513@mb-m18.aol.com
> > Write a program that reads in the size of the side of a square and
> > then prints a hollow square of that size out of asterisks and blanks.
> > Your program should work for squares of all side sizes between 1 and
> > 20. For example, if your program reads a size of 5, it should print
> >
> > *****
> > * *
> > * *
> > * *
> > *****
> >
> >
> > Am I supposed to type all of the possible outputs between 1 and 20
> > and use a selection structure to choose which one? That's the only
> > thing I can think of. is there another way?
>
>
> You type out the outputs for n==1 and n==2. For n>2, you can construct the
> square on the spot. Just divide up the square into its component lines:
>
> Line 1: n asterisks.
> Lines 2 to n-1: a left asterisk, followed by n-2 spaces followed by a right
> asterisk.
> Line n: n asterisks.

Your algorithm above works fine for n == 1 and n == 2. One should not
have a special case for those situations.



Relevant Pages

  • Re: Exercise from C++ How to program Cyber classroom 4th ed.
    ... "Bruce Lee 646" wrote in message ... > then prints a hollow square of that size out of asterisks and blanks. ... Lines 2 to n-1: a left asterisk, followed by n-2 spaces followed by a right ...
    (comp.lang.cpp)
  • Exercise from C++ How to program Cyber classroom 4th ed.
    ... Write a program that reads in the size of the side of a square and then prints ... a hollow square of that size out of asterisks and blanks. ... selection structure to choose which one? ...
    (comp.lang.cpp)
  • Re: How inaccurate is a 555 or 7555 REALLY?
    ... on making a tiny quartz crystal divide down to 420hz in a tiny package ... Sine wave output preferred, but I think square ...
    (sci.electronics.design)
  • Re: Number with parameter...
    ... A general rational solution, in terms of a parameter u, is: ... I don't know how to transfer with u. so, I need your advice. ... To make y you take u, square it, subtract x, multiply by x, and divide by 2u. ...
    (sci.math)
  • Re: Standard Deviation
    ... If you divide that value by N or N-1 you get the variance, which is s squared if you divide by N, or sigma squared if you divide by N-1. ... From that value again, you get the standard deviation by extracting the square root, which is either s or sigma. ...
    (borland.public.delphi.non-technical)