Difference between revisions of "CSC231 Final Exam 2012"
Line 30: | Line 30: | ||
** have 2 arrays A and B filled with floating point numbers, find the index where the index where A[i] + B[i] is max. | ** have 2 arrays A and B filled with floating point numbers, find the index where the index where A[i] + B[i] is max. | ||
--> | --> | ||
− | =Problem #1 ( | + | =Problem #1 (2 points)= |
<code><pre> | <code><pre> | ||
Line 304: | Line 304: | ||
− | =Problem #2 ( | + | =Problem #2 (1 point)= |
We saw that Python seems to be more "clever" than other languages when it deals with numbers. | We saw that Python seems to be more "clever" than other languages when it deals with numbers. | ||
Line 312: | Line 312: | ||
The program then computes the sum of the ten numbers as stored in the list. That's sum1. Next it sorts the list in increasing order and computes the sum again, this time saving it into sum2. Finally, it reverses the list so that it is sorted in decreasing order, and computes the sum of the numbers which it stores in sum3. It then compares sum1, sum2, and sum3, and displays the list and the sums if these are not equal. | The program then computes the sum of the ten numbers as stored in the list. That's sum1. Next it sorts the list in increasing order and computes the sum again, this time saving it into sum2. Finally, it reverses the list so that it is sorted in decreasing order, and computes the sum of the numbers which it stores in sum3. It then compares sum1, sum2, and sum3, and displays the list and the sums if these are not equal. | ||
− | '''Question 1''': Explain why the 3 sums are usually the same, but ''sometimes'' not equal. Base your | + | '''Question 1''': Explain why the 3 sums are usually the same, but ''sometimes'' not equal. Base your explications on the 32-bit IEEE Floating-Point format which we saw in class. |
'''Question 2''': What recommendations would you make when one has to compute the sum of several floating-point numbers? | '''Question 2''': What recommendations would you make when one has to compute the sum of several floating-point numbers? | ||
Line 318: | Line 318: | ||
'''Question 3''': What test could you use when you are given a list of numbers to figure out whether the sum ''might'' not be correct when the addition is performed? | '''Question 3''': What test could you use when you are given a list of numbers to figure out whether the sum ''might'' not be correct when the addition is performed? | ||
− | + | ||
− | |||
Store your answers in a text file (not a Word doc file, please!) called '''final2.txt''' and submit it as follows: | Store your answers in a text file (not a Word doc file, please!) called '''final2.txt''' and submit it as follows: | ||