Lecture 3 By Zahoor Ahmad Khan email@example.com Source of this lecture: ---- (Material is taken from World Wide Web, recommended books, online tutorials)-----. Introduction to Computer Programming. What is a Computer Program?.
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
Print Command for
One of the simplest algorithms is to find the largest number in an (unsorted) list of numbers. The solution necessarily requires looking at every number in the list, but only once at each. From this follows a simple algorithm, which can be stated in a high-level description English prose, as:
Assume the first item is largest.
Look at each of the remaining items in the list and if it is larger than the largest item so far, make a note of it.
The last noted item is the largest in the list when the process is complete.
Written in prose but much closer to the high-level language of a computer program, the following is the more formal coding of the algorithm in pseudo code :
Input: A non-empty list of numbers L.
Output: The largest number in the list L.
largest ← L0
for eachitemin the list L≥1, do
if the item > largest, then
largest ← the item