백준 11720 숫자의 합

Console Programming/C# Console 2019. 10. 1. 15:41
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
 
namespace _11720
{
    class Program
    {
        static void Main(string[] args)
        {
 
            int input = int.Parse(Console.ReadLine());
            string str = Console.ReadLine();
            int[] num = new int[input];
            int sum = 0;
            
            for (int j = 0; j < input; j++)
            {
                num[j] = Convert.ToInt32(str[j])-48;
            }
            
            for (int i = 0; i < input; i++)
            {
                sum = sum + num[i];
            }
            Console.WriteLine(sum);
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

 

: