Algorithm to find smallest element

  • Thread starter Thread starter Bucs44
  • Start date Start date
  • Tags Tags
    Algorithm Element
Bucs44
Messages
57
Reaction score
0
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?
 
Physics news on Phys.org
How could it be wrong?
 
I'm just wondering if I worded it correct and it constitutes as an algorithm?
 
It's perfect.
 
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!
 
Depends on where you think the problem statement ends and the algorithm starts. Maybe we need a new punctuation symbol here.
 
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
 
Back
Top