BorislavBorisov

33.05.Astrological Digits мое решение

Nov 4th, 2015
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.91 KB | None | 0 0
  1. using System;
  2. class AstrologicalDigits
  3. {
  4.     static void Main()
  5.     {
  6.         string N = Console.ReadLine();
  7.         FindSumOfDigits(N);
  8.     }
  9.  
  10.     static void FindSumOfDigits(string N)
  11.     {
  12.         char[] arr = N.ToCharArray();
  13.         int sum = 0, index = 0;
  14.  
  15.         while (true)
  16.         {
  17.             if (arr[index] != '-' && arr[index] != '.')
  18.             {
  19.                 sum += arr[index] - '0';
  20.                 if (index == arr.Length - 1 && sum > 10)
  21.                 {
  22.                     index = -1;
  23.                     //arr = Convert.ToString(sum).ToCharArray();
  24.                     arr = sum.ToString().ToCharArray();
  25.                     sum = 0;
  26.                 }
  27.                 if (index == arr.Length - 1 && sum < 10)
  28.                 {
  29.                     Console.WriteLine(sum);
  30.                     return;
  31.                 }
  32.             }
  33.             index += 1;
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment