Advertisement
Asinka

02. AstrologicalDigits (7 Dec 2011 Morning)

Dec 26th, 2012
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4.  
  5. class AstrologicalDigits
  6. {
  7.     static void Main()
  8.     {
  9.         string numberN = Console.ReadLine();
  10.         decimal sum = 0;
  11.        
  12.         do
  13.         {
  14.             sum = 0;
  15.             int startIndex = 0;
  16.  
  17.             while (startIndex < numberN.Length)
  18.             {
  19.                 string digit = numberN.Substring(startIndex, 1);
  20.                 if (digit != "-" && digit != "." && digit != ",")
  21.                 {
  22.                     decimal number = decimal.Parse(digit);
  23.                     //Console.WriteLine(number + " ");
  24.                     sum = sum + number;
  25.                 }
  26.                 startIndex++;
  27.  
  28.                
  29.             }
  30.  
  31.             numberN = Convert.ToString(sum);
  32.             //Console.WriteLine(sum);
  33.         }
  34.         while (sum > 9);
  35.  
  36.         Console.WriteLine(sum);
  37.        
  38.        
  39.  
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement