HW # 7
CSC 105
For the following set of problems please write down
Problem # 1: Given a list of Numbers to find the largest number in this list .
Example : Given List à 2 4 6 7 9 8 3
The largest number is 9.
Natural Language Description :
Read in the first number from the list , store it in largest .
As long as it is not the end of the list keep reading in the next number in the list , if this number is larger than largest , store it in largest .
Pseudo Code :
Read in the number ,store it in Largest While(not end of list) Read in the nextnumber If nextnumber > Largest then Largest = nextnumberEnd whileReturn Largest
Problem # 2 : Given a list of numbers to find the sum of two consecutive numbers according to their order of occurrence in the list and to write these sums to another list .
Example : Given List1 à 2 3 8 5 4 11 13 12 10
List2 à 5 11 13 9 15 24 25 22
Natural Language Description :
Read in present and next number , add them and store in list2.
As long as there are numbers in the list repeat the following cycle.
Assign next to present . Read in the next number in the list1 and store it in next . Add present and next and store it in sum . Print sum , store it in list2.
Pseudo Code :
Read first number in the list and store in present
While ( not end of list )
Read next number in the list and store in next
Sum = present + next
Store sum in list 2
Print sum
Present = next
End_While
Return
Problem # 3: To read in the numbers from a list and to write these out to another list in reverse order , given that the number of values in this list is 8 ( hint : Use the for loop ).
Example : given list à 3 6 8 1 9 5 7 2
Required list à 2 7 5 9 1 8 6 3
Natural Language description :
Read in the first value from the given list write it as the last value in the required list . Repeat the following cycle as long as there are numbers in the first list . Read in the value in the next position of the given list , store it in the preceding position of the required list .
Pseudo Code :
For ( count =1 ; count < 9 ; count= count +1 )
Read in the value in position (count) of given list ,
Store it in position (9-count) of the required list.
End_for