bacco

Сумиране на цифрите на число ; Sum Digits

Feb 19th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.39 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Купа
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.            
  10.             var n = int.Parse(Console.ReadLine());
  11.  
  12.             int result = 0;
  13.  
  14.            do
  15.             {
  16.                 result +=  n % 10;
  17.                 n /= 10;
  18.  
  19.             } while (n > 0);
  20.  
  21.             Console.WriteLine(result);
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment