Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace DigitCounter
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. Console.WriteLine("Count Number of Digits of a Given Number");
  14. int n = Convert.ToInt32(Console.ReadLine());
  15. int remainder = 0, count = 0; string sum = string.Empty;
  16. string N = string.Empty;string f=string.Empty;
  17. N = n.ToString();
  18. while (n != 0)
  19. {
  20. remainder = n % 10;
  21. sum = sum + remainder;
  22. n = n / 10;
  23. count++;
  24. }
  25. for (int i = sum.Length-1; i >= 0; i--)
  26. {
  27. f = f + sum[i];
  28. }
  29. if (f== N)
  30. {
  31. Console.WriteLine("The number of digits in the number is={0}", count);
  32. }
  33. Console.ReadLine();
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement