Case 1
Case 2
Case 3
Solution:
Case 1.
1. Reqeust n
2. Deteremine sumSquare
2.1 count = 1
2.2 sumSquare = 0
2.3 count = count + 1
2.4 Request Xi
2.5 sumSquare = sumSquare + (Xi * Xi)
2.6 Repeat 2.3 to 2.5 until count <= n
3. Display sumSquare
2. Deteremine sumSquare
2.1 count = 1
2.2 sumSquare = 0
2.3 count = count + 1
2.4 Request Xi
2.5 sumSquare = sumSquare + (Xi * Xi)
2.6 Repeat 2.3 to 2.5 until count <= n
3. Display sumSquare
Case 2
1. Request n
2. Calculate squareSum
2.1 count = 1
2.2 sum = 0
2.3 squareSum = 0
2.4 count = count + 1
2.5 Request Xi
2.6 sum = sum + Xi
2.7 Repeat 2.4 to 2.6 until count <= n
2.8 squareSum = squareSum + (sum * sum)
3. Display squareSum
2. Calculate squareSum
2.1 count = 1
2.2 sum = 0
2.3 squareSum = 0
2.4 count = count + 1
2.5 Request Xi
2.6 sum = sum + Xi
2.7 Repeat 2.4 to 2.6 until count <= n
2.8 squareSum = squareSum + (sum * sum)
3. Display squareSum
Case 3
1 Request n
2. Deteremine variance
2.1 count = 1
2.2 sum = 0
2.3 sumSquare = 0
2.4 squareSum = 0
2.5 variance = 0
2.6 count = count + 1
2.7 Request Xi
2.8 sumSquare = sumSquare + (Xi * Xi)
2.9 sum = sum + Xi
3.0 Repeat 2.6 - 2.8 until count = n
3.1 squareSum = squareSum + (sum * sum)
3.2 variance = (sumSquare - squareSum) / (n - 1)
4. Display variance
2. Deteremine variance
2.1 count = 1
2.2 sum = 0
2.3 sumSquare = 0
2.4 squareSum = 0
2.5 variance = 0
2.6 count = count + 1
2.7 Request Xi
2.8 sumSquare = sumSquare + (Xi * Xi)
2.9 sum = sum + Xi
3.0 Repeat 2.6 - 2.8 until count = n
3.1 squareSum = squareSum + (sum * sum)
3.2 variance = (sumSquare - squareSum) / (n - 1)
4. Display variance
Explanation:All this should be familiar to you by now, if not you need to study other examples.
Notice that in cases 1 and 2 above that we picked lines 2.2, 2.5 and 2.2, 2.3, 2.6, 2.8 respectively and drop it in case 3. In other words line 3.2 of case 3 is just case 1 minus case 2 divide by n - 1. Therefore case 3 combined the functions of cases 1 and 2 and extra function in line 3.2.
SHARE THIS POST WITH YOUR FRIENDS...::
Tweet
0 comments:
Leave a Reply