Advertisement
Dianov

Data Types and Variables - Exercise (02. Sum Digits)

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