Re: sorting 3 input numbers
From: Chris F.A. Johnson (c.fa.johnson_at_rogers.com)
Date: 10/21/03
- Next message: Chris F.A. Johnson: "Re: grep prolem"
- Previous message: Barry Margolin: "Re: pipes and $1"
- In reply to: Stefan Dask: "sorting 3 input numbers"
- Next in thread: Stephane CHAZELAS: "Re: sorting 3 input numbers"
- Reply: Stephane CHAZELAS: "Re: sorting 3 input numbers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Chris F.A. Johnson: "Re: grep prolem"
- Previous message: Barry Margolin: "Re: pipes and $1"
- In reply to: Stefan Dask: "sorting 3 input numbers"
- Next in thread: Stephane CHAZELAS: "Re: sorting 3 input numbers"
- Reply: Stephane CHAZELAS: "Re: sorting 3 input numbers"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|