saimun1

Sum of digits

Jul 21st, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.53 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 test
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.             int sum = 0;
  15.             do
  16.             {
  17.                 sum += n % 10;
  18.                 n = n / 10;
  19.             }
  20.             while (n>0);
  21.             Console.WriteLine("Sum of digits {0}", sum);
  22.             Console.ReadLine();
  23.         }
  24.     }
  25. }
Add Comment
Please, Sign In to add comment