ellapt

AstrologDigits

Dec 18th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. using System;
  2.  
  3. class AstrologDigits
  4. {
  5. static void Main()
  6. {
  7. ulong astroSum = 0;
  8. while (true)
  9. {
  10. int chDigit = Console.Read();
  11. if (chDigit == (int)'\n' || chDigit == (int)'\r' || chDigit == -1)
  12. {
  13. break;
  14. }
  15. if (chDigit >= '0' && chDigit <= '9')
  16. {
  17. ulong digit = (ulong)chDigit - (ulong)'0';
  18. astroSum = astroSum + digit;
  19. }
  20. }
  21.  
  22. while (astroSum > 9)
  23. {
  24. ulong tempAstroSum = 0;
  25. while (astroSum > 0)
  26. {
  27. ulong lastDigit = astroSum % 10;
  28. tempAstroSum = tempAstroSum + lastDigit;
  29. astroSum = astroSum / 10;
  30. }
  31. astroSum = tempAstroSum;
  32. }
  33.  
  34. Console.WriteLine(astroSum);
  35.  
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment