Advertisement
Guest User

Untitled

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