static void Main(string[] args)
{
int addedValue = AddNumber(23325);
Console.WriteLine($"The sum of numbers in the given number is {addedValue}");
Console.ReadLine();
}
private static int AddNumber(int v)
{
string num = v.ToString();
int sum = 0;
for (int i = 0; i < num.Length; i++)
{
sum += int.Parse(num.Substring(i, 1));
}
return sum;
}
No comments:
Post a Comment