Advertisement
hawzze

sum of the digits

May 12th, 2021
823
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.44 KB | None | 0 0
  1. sing System;
  2.  
  3. namespace ConsoleApp7
  4. {
  5.     class Program1
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string input = Console.ReadLine();
  10.             int sum = 0;
  11.             for (int i = 0; i < input.Length; i++)
  12.             {
  13.                 int currentNumber = (int)Char.GetNumericValue(input[i]);
  14.                 sum += currentNumber;
  15.  
  16.             }
  17.             Console.WriteLine(sum);
  18.         }
  19.     }
  20. }
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement