Re: sorting 3 input numbers

From: Chris F.A. Johnson (c.fa.johnson_at_rogers.com)
Date: 10/21/03


Date: 21 Oct 2003 14:59:25 GMT

On Tue, 21 Oct 2003 at 10:10 GMT, Stefan Dask wrote:
> hi again,
>
> thank you for your responses. let me tell you briefly what is
> requested:
>
> 1. we are in bourne or c shell.
> 2. suppose that we are entering 3 integer numbers as input.
> 3. when the ./scripfile (or the name of the file) is activated,
> "please enter three integer numbers."
> 4. after that, taken 3 input numbers are listed in ascending order.
>
> example: suppose that we enter three integers such as 16 40 8.
>
> and entered 3 integers are sorted in ascending order such as 8 16 40
> as output..

    We're STILL waiting for you to post your attempts, but, since
    several others have already posted solutions, here's mine:

echo "Enter three numbers:"
read n; set x $n; shift
[ $1 -gt $2 ] && { set x $2 $1 $3; shift; }
[ $2 -gt $3 ] && { set x $1 $3 $2; shift; }
[ $1 -gt $2 ] && { set x $2 $1 $3; shift; }
echo $1 $2 $3

-- 
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2003, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License


Relevant Pages

  • Re: Issue with Selected Text Colour
    ... When I read the other responses I did feel bit of a fool! ... By the way I have just read the thread about Australian Thanksgiving and thought it was so funny. ... Certainly lightens thinks up if you are feeling a little bit over awed with PowerPoint.I read all the postings even though I don't know what half of them mean, perhaps a little bit of the information I read about may just come to the front when needed. ... Echo thanks again for response. ...
    (microsoft.public.powerpoint)
  • entering bios with Labview serial vis
    ... am able to enter the bios with hyperterminal and see all the responses ... information to the bios in labview with either the serial vis or visa I ... that hyperterminal does automatically to get this info to echo out the ... when automating with expect.  However, in labview, this does not ...
    (comp.lang.labview)
  • Re: 6 months!
    ... Not to worry about any responses other than this one from me, ... giant "thank you". ... > Echo wrote: ... > I have had responses to the picture I posted for your HOF... ...
    (alt.support.stop-smoking)
  • Re: Capturing the output of transparent commands (e.g., @@CONS T,D D).
    ... After @@ECHO ON was entered, ... The Theorem Theorem: If If, ...
    (comp.sys.unisys)