Solution:
Major Steps
1. Request Data
2. Calculate sum
3. Display sum
Stepwise Refinement
1. Request Data
1.1 Request n
2. Determine score
2.1 sum = 0
2.2 count = 1
2.3 Request Xi
2.4 sum = sum + Xi
2.6 Repeat 2.3 and 2.4 until count <= n
3. Display sum
1. Request Data
2. Calculate sum
3. Display sum
Stepwise Refinement
1. Request Data
1.1 Request n
2. Determine score
2.1 sum = 0
2.2 count = 1
2.3 Request Xi
2.4 sum = sum + Xi
2.6 Repeat 2.3 and 2.4 until count <= n
3. Display sum
Explanation:
Why
is the sum initialised to 0? Because 0 + any number (the first number
of Xi) is that number and that is it. Just like in the product example,
this is how the sum will be computed if the numbers Xi, supplied are:2, 6, 3, 5, 4, 1.That is n = 6 then sum will be:
sum = 0 + 2,Then line 3 will display 21 as the summation of the numbers. When summing at each point the previous value of sum id erased and a new value assigned to it. For the first value sum = 0 + 2, here sum = 2. The previous value '0' has being erased and this process continues until the numbers xi, are exhausted.
sum = 2 + 6,
sum = 8 + 3,
sum = 11 + 5,
sum = 16 + 4,
sum = 20 + 1.
You have to initialise count to be count = 1. The is from the equation given above. That count will start from ‘i’; where i start from 1 to n (i = 1, …, n).
The next example will teach you how to count from any integer number to any integer number.
SHARE THIS POST WITH YOUR FRIENDS...::
Tweet
0 comments:
Leave a Reply