Skip to content

Instantly share code, notes, and snippets.

@andor44
Created March 10, 2013 21:15
Show Gist options
  • Save andor44/5130459 to your computer and use it in GitHub Desktop.
Save andor44/5130459 to your computer and use it in GitHub Desktop.
számösszeg
using System;
namespace teststuff
{
class Program
{
static ulong szamjegy_osszeg(ulong x)
{
ulong ossz = 0;
ulong lim = (ulong)Math.Ceiling(Math.Log10(x));
for (ulong i = lim; i > 0; i--) {
ulong asd = ((x % (ulong)Math.Pow(10, i)) - (x % (ulong)Math.Pow(10, i-1))) / ((i == 0) ? (1) : ((ulong)Math.Pow(10, i-1)));
ossz += asd;
}
return ossz;
}
public static void Main(string[] args)
{
ulong x = ulong.Parse(Console.ReadLine());
Console.WriteLine("összeg: " + szamjegy_osszeg(x).ToString());
ulong osszeg = x;
while ((osszeg = szamjegy_osszeg(osszeg)) > 10) {
Console.WriteLine("összeg: " + szamjegy_osszeg(osszeg).ToString());
}
Console.ReadKey(true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment