We repeat the same procedure for the third qubit. Note here that the third qubit is not necessary at this stage because the maximum value of the sum of the values of three qubits is 3.
Let us check that the above quantum circuit indeed generates the correct value in the ancillary register.
Extracts the sum from the output state in the ancillary register. In actual situation, one should perform the measurement on the ancillary register in the computation basis.