This preview shows page 1. Sign up to view the full content.
Unformatted text preview: a proper algorithm Solves a problem Unambiguous instructions Tests if a user entered number is prime Completes in a finite amount of time given proper input What if step 4 didn't compare the divisor with the square root of the user's number? Pseudocode So far we've used natural language to describe algorithms It is helpful to describe algorithms in pseudocode (almost code) An algorithm written in pseudocode is then easily coded in any give programming language Pseudocode Digital Clock Example from Study Guide set hour to 0 set minute to 0 set second to 0 repeat forever: set second to second + 1 if second is more than 59, then set second to 0 set minute to minute + 1 if minute is more than 59, then set minute to 0 set hour to hour + 1 if hour is more than 23, then set hour to 0 write "hour :minute:second" wait for 1 second Pseudocode Pseudocode for prime number example set divisor to 2 write "Enter an integer greater than 2" read userNumber repeat whil...
View
Full
Document
This note was uploaded on 09/06/2013 for the course COMPUTING FE1008 taught by Professor Johnarnold during the Fall '11 term at Mapúa Institute of Technology.
 Fall '11
 JohnArnold

Click to edit the document details