Advertisement
Spocoman

02. Sum Digits

Jan 17th, 2022
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.46 KB | None | 0 0
  1. using System;
  2.  
  3. namespace SumDigits
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int num = int.Parse(Console.ReadLine());
  10.             int currentDigit = num;
  11.             int sum = 0;
  12.  
  13.             for (int i = 0; i < num.ToString().Length; i++)
  14.             {
  15.                 sum += currentDigit % 10;
  16.                 currentDigit /= 10;
  17.             }
  18.             Console.WriteLine(sum);
  19.         }
  20.     }
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement