I have a number as N=2345
If I sum them the result will be 2+3+4+5 =14;
If I further sum them it will be 1+4 = 5; which is a single digit;
How to do this?
public static int FindSingleDigit(int N)
{
var sum = 0;
int count = 0;
while (N != 0)
{
sum = sum + (N % 10);
N = N / 10;
count++;
}
if (sum >= 10) return FindSingleDigit(sum);
else return sum;
}
Invoke it as
var result = FindSingleDigit(2345);