Advertisement
naskootbg

Crooked Digits Mock Exam 1

Jan 3rd, 2022
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. class Program
  7. {
  8. static void Main()
  9. {
  10. var n = Console.ReadLine();
  11. var split = n.ToCharArray();
  12. int sum = 0;
  13. int tint = 0;
  14.  
  15. foreach (var ch in split)
  16. {
  17. if (Char.IsDigit(ch))
  18. {
  19. tint = ch - '0';
  20. sum += tint;
  21. if (sum > 9)
  22. {
  23. sum = 0;
  24. }
  25. }
  26.  
  27. }
  28.  
  29. n = sum.ToString();
  30. Console.WriteLine(n);
  31.  
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement