MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / sumofdigits

Function sumofdigits

Misc/SumOfAllDigits/solution2.cpp:9–17  ·  view source on GitHub ↗

Find sum of digits of a number

Source from the content-addressed store, hash-verified

7
8// Find sum of digits of a number
9long int sumofdigits(long int n)
10{
11 int d;
12 d=n%10;
13 if(n<10)
14 return d;
15 else
16 return d+sumofdigits(n/10);
17}
18
19// Recursively find sum of digits till the number is single digit
20long int sumuptosingledigit(long int n)

Callers 2

sumuptosingledigitFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected