Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. static int CountTimes(string userInput)
  2. { int number = int.Parse( userInput);
  3. int sum = 0;
  4. int newValue = number;
  5. int count = 0;
  6.  
  7. while (newValue > 0)
  8. {
  9.  
  10. number = newValue;
  11. sum = 0;
  12. while (number > 0)
  13. {
  14.  
  15. sum += number % 10;
  16. number /= 10;
  17.  
  18. }
  19. newValue = newValue - sum;
  20.  
  21. count++;
  22. }
  23. return count;
  24. }
  25. static void Main(string[] args)
  26. {
  27.  
  28. Console.WriteLine("введите число");
  29. string userInput = Console.ReadLine();
  30. Console.WriteLine("вычитaние можно выполнить: "+ CountTimes(userInput)+" раз");
  31.  
  32.  
  33.  
  34. Console.ReadKey();
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement