Advertisement
Guest User

09. Sum Digits

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