write an algorithm and draw a flowchart