| 1 | class Solution { |
| 2 | public: |
| 3 | int addDigits(int num) { |
| 4 | //If number is 0 return 0 |
| 5 | if(num==0) |
| 6 | { |
| 7 | return 0; |
| 8 | } |
| 9 | //if the number is single digit return the number itself |
| 10 | if(num>0&&num<=9) |
| 11 | { |
| 12 | return num; |
| 13 | } |
| 14 | //if number is divisible by 9 then by the divisibility test that a number divided by 9 has |
| 15 | //the sum of digits as 9 return 9 |
| 16 | |
| 17 | if(num%9==0) |
| 18 | { |
| 19 | return 9; |
| 20 | } |
| 21 | //else return the remainder on dividing by 9. |
| 22 | return num%9; |
| 23 | } |
| 24 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected