Advertisement
hawzze

sum of the digits

May 12th, 2021
668
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.36 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp2
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int n =int.Parse(Console.ReadLine());
  10.            int sum = 0;
  11.             while (n != 0)
  12.             {
  13.                 sum += n % 10;
  14.                 n /= 10;
  15.             }
  16.             Console.WriteLine(sum);
  17.         }
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement