Posted by Kimberly on Friday, August 24, 2012 at 10:35pm.
After reviewing an algorithm that allowed a user to enter 3 different numerical values, if statements were used to find the smallest value.
Smallest of five: The assignment is to determine which method (either nested conditions, sequential compound conditions, nested and compound conditions, or using a placeholder variable) would be the best method for determining the smallest number of five user inputs which may contain duplicate values AND to write the algorithm for the problem.
We have not studied arrays or loops - only if statements so far. We are using Visual Logic or writing out if/else statements to arrive at the answer.
I wrote out how to find the smallest number of three numbers, but I don't know how to find the smallest number of five if there are two inputs that are the same number.
Should I use sequential or nested and compound conditions or a placeholder variable method?
Here's what I have so far:
If num1 < num2 true then
if num1 < num3 true then
if num1 < num4 true then
if num1 < num5 true then
output &num1 "is the smallest."
Else if num1 = num2 true then
output &num "numbers are equal."
Else if num1 = num2 false then
if num1 > num3 true then...
Anybody understand any of this? Can you help me with the thinking part of the logic on how to come up with how to solve this so I can get it on paper to think about before I get it into my head wrong?
Kimberly (42 year old student...now you understand...)
- Computer Science - Steve, Saturday, August 25, 2012 at 12:21am
I'd use a placeholder value, and compare it against the other values as they come in:
if num2 < small then small = num2
likewise for num3,4,5
output small "is the smallest"
If you aren't interested in reporting any duplicate values, then that's all there is to it. In fact, unless you want to report something about the incoming numbers, you can just use "num" for the input value each time.
Answer this Question
probability - out of 250 students interviewed at a community college, 90 were ...
Visual Basic (Computer Programming) - ALGORITHM EXERCISES 1. Wilma Peterson is ...
Computer Science - Give a modular exponentiation algorithm that examines the ...
Science 7R Help! - Science Hw - TB pg 621 Reviewing Vocab. 1-10 Checking Concept...
English - 1. After each meal, I drew a chart with /on a computer that I had ...
Computer - How to write an algorithm to find the fibonacci series ??? Help:/
Computer Studies-Algorithm - don know
computer - What does tenure track, part time instructor of computer science does...
Computer Science - Use the Infix to Prefix algorithm shown in class to translate...
Computer Science - Suppose we are trying to solve Simon's problem with n=4. We ...