Advertisement
NikolaySpasovTriset

sumDigits

Oct 11th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. using System;
  2.  
  3. class testLoops
  4. {
  5. static void Main()
  6. {
  7. int n = int.Parse(Console.ReadLine());
  8. int lastDigit = 0;
  9. int sumDigits = 0;
  10. do
  11. {
  12. lastDigit = n % 10;
  13. n = n / 10;
  14. sumDigits += lastDigit;
  15. } while (n != 0);
  16.  
  17. Console.WriteLine(sumDigits);
  18. }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement