Created
March 10, 2013 21:15
-
-
Save andor44/5130459 to your computer and use it in GitHub Desktop.
számösszeg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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