Advertisement
aggressiveviking

09.SumDigits

Mar 2nd, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.42 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _09.SumDigits
  4. {
  5.     class SumDigits
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             var n = int.Parse(Console.ReadLine());
  10.             var sum = 0;
  11.  
  12.             do
  13.             {
  14.                 sum = sum + (n % 10);
  15.                 n = n / 10;
  16.             }
  17.             while (n > 0);
  18.  
  19.             Console.WriteLine($"Sum of digits: {sum}");
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement