본문 바로가기

Programming/BaekJoon

[C++] 백준 11720번 : 숫자의 합


https://www.acmicpc.net/problem/11720




#include <iostream>

using namespace std;

int main() {

int n;

cin >> n;

char *input = new char[n+1];

for (int i = 0; i < n; i++) 

cin >> input[i];

int sum = 0;

for (int i = 0; i < n; i++) 

sum = (int)input[i]-48 + sum;

cout << sum << "\n";

}