Code 5: Technique to find the sum of all digits in a number.

Problem Description:
We need to extract all the digits one by one from the number and add them up. By using the digit extraction technique we know that we will be able to get the digits one by one. As soon as we get the required digit we will just add them up using the summation technique sum=sum+r (as in here r  contains the required digit)As we see here using two simple techniques learned earlier the problem becomes simpler to understand and code.


No comments:

Post a Comment