Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- //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.
- //Input
- //The input data should be read from the console.
- //The only line in the input contains a number N, which can be integer or real number (decimal fraction).
- //The input data will always be valid and in the format described. There is no need to check it explicitly.
- //Output
- //The output data should be printed on the console.
- //You must print the calculated astrological digit of the number N on the first and only line of the output.
- class Program
- {
- static void Main()
- {
- string num = Console.ReadLine();
- int sum = new int();
- foreach(char digit in num)
- {
- if ((digit != '.')&&(digit != '-'))
- {
- sum += digit - '0';
- }
- }
- if (sum % 9 == 0 && sum != 0)
- {
- Console.WriteLine(9);
- }
- else
- {
- Console.WriteLine(sum % 9);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement