Add Digits
The snippet can be accessed without any authentication.
Authored by
Kiryuu Sakuya
Program.cs 640 B
using System;
using System.Collections.Generic;
namespace leetcodecsharp
{
class Program
{
public static int AddDigits(int num)
{
if (num == 0)
return 0;
int i = num;
while (i.ToString().Length != 1)
{
int j = 0;
foreach (char c in i.ToString())
j = j + (int)char.GetNumericValue(c);
i = j;
}
return i;
}
public static void Main(string[] args)
{
int a = 52515;
Console.WriteLine(AddDigits(a));
}
}
}
Please register or sign in to comment