Advertisement
CR7CR7

croocked digit

Nov 4th, 2022
1,150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.65 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Telerik
  4. {
  5.     public class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             var input = Console.ReadLine().ToCharArray() ;          
  10.            
  11.             while (input.Length > 1)
  12.             {
  13.                 int result = 0;
  14.                 for (int i = 0; i < input.Length; i++)
  15.                 {
  16.                     if (char.IsDigit(input[i]))
  17.                     {
  18.                         result += input[i] - 48;
  19.                     }
  20.                 }
  21.                 input = result.ToString().ToCharArray();
  22.             }
  23.             Console.WriteLine(input) ;
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement