Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class AstrologicalDigits
- {
- static void Main()
- {
- //Telerik Academy
- //The astrological digit of a given number N is a digit calculated by the number's digits by a special algorithm. The algorithm performs the following steps:
- //(1) Sums the digits of the number N and stores the result back in N.
- //(2) If the obtained result is bigger than 9, step (1) is repeated, otherwise the algorithm finishes.
- //The last obtained value of N is the result, calculated by the algorithm.
- string numberInput = Console.ReadLine();
- int sum = 0;
- string buffer = numberInput;
- do
- {
- sum = 0;
- foreach (char item in buffer)
- {
- if (item != '.' && item != '-')
- {
- sum += (int)item - '0';
- }
- }
- if (sum <= 9)
- {
- break;
- }
- else
- {
- buffer = Convert.ToString(sum);
- }
- } while (sum > 9);
- Console.WriteLine(sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement