Advertisement
serd2011

Сумма цифр цисла

Sep 5th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.65 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 summ_cifr_v_chisle
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int x,b,summ=0;
  14.             Console.Write("Введите число >>> ");
  15.             x = int.Parse(Console.ReadLine());
  16.             summ += x % 10;
  17.             b = x / 10;
  18.             while (b!=0)
  19.             {
  20.                 summ += b % 10;
  21.                 b /= 10;
  22.             }
  23.             Console.Write("Сумма цифр >>> " + summ.ToString());
  24.             Console.ReadLine();
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement