Common Algorithms 101

1. Finding the smallest of 3 numbers:



if first is smaller than second
   if first is smaller than third, then the smallest is first
   else smallest is third since we know that first is smaller than second.
else
   if second is smaller than third, then smallest is second
   else third is smallest since we know that second is smaller than first


2. Finding the largest number of a set of numbers:


Prompt the user to input the first number
Assign the input to largest variable
Initialize condition to true
While the users says “y”
	Prompt the user to input the next number
	assign the new value to a variable
	compare the two variables 
	assign the larger of the two variables to largest variable
        find out if the user wants to input more data, if “y”, go back to while
if “n”, display the largest with a message.



3. Finding the mean or average of a set of numbers:


 

Initialize condition to true
Initialize counter variable to one
Prompt the user to input the first number
Assign input to total variable
while the user says “y”
	Prompt the user to input the next number
	assign the new value to a variable
	add the new value to total variable
	find out if the user wants to input more data, if “y”, go back to while
	increment the counter variable
if “n”, find the average by dividing the total variable by the counter variable.
Display the average with a message.