Algorithm to find smallest element

1. Jan 17, 2007

Bucs44

I'm working on an algorithm that finds the smallest element among a, b, and c.

Here is what I have so far:

Input: a,b,c
Output: small; smallest element in the sequence a,b,c
a = 2, b = 4, c = 3
Small = a
If b < small, then small = b
If c < small, then small = c

Is this right?

2. Jan 17, 2007

Dick

How could it be wrong?

3. Jan 17, 2007

Bucs44

I'm just wondering if I worded it correct and it constitutes as an algorithm?

4. Jan 17, 2007

Dick

It's perfect.

5. Jan 17, 2007

HallsofIvy

Staff Emeritus
Well, except for one thing: According to the algorithm, it gets a, b, c as input and then immediately sets a= 2, b= 4, c= 3. No matter what a, b, c are, this algorithm outputs 2!

6. Jan 17, 2007

Dick

Depends on where you think the problem statement ends and the algorithm starts. Maybe we need a new punctuation symbol here.

7. Jan 17, 2007

Bucs44

I actually added the a = 2, b = 4, c = 3 portion as I thought that was what was needed in order to perform the algorithm