Advertisement
ivanov_ivan

SumingNumbers

Aug 21st, 2016
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 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 SumNumbers
  8. {
  9.     class SumNumbers
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int number = int.Parse(Console.ReadLine());
  14.             var sum = 0;
  15.  
  16.             while(number != 0)
  17.             {
  18.                 sum += number % 10;
  19.                 number /= 10;
  20.             }
  21.             Console.WriteLine(sum);
  22.  
  23.             /*5634 % 10 = 4;
  24.             5634 / 10 = 563;
  25.             563 % 10 = 3;
  26.             563 / 10 = 56;
  27.             56 % 10 = 6;
  28.             56 / 10 = 5;
  29.             5 % 10 = 5;
  30.             5 / 10 = 0;*/
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement