문제
문자열 my_string이 매개변수로 주어집니다. my_string안의 모든 자연수들의 합을 return하도록 solution 함수를 완성해주세요.
솔루션
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
// 파라미터로 주어지는 문자열은 const로 주어집니다. 변경하려면 문자열을 복사해서 사용하세요.
int solution(const char* my_string) {
int answer = 0;
for(int i = 0; i < strlen(my_string);i++)
{
if(isdigit(my_string[i]))
answer += (my_string[i] - 48);
}
return answer;
}
https://school.programmers.co.kr/learn/courses/30/lessons/120851
'프로그래머스코딩테스트연습풀이 > C언어' 카테고리의 다른 글
[프로그래머스/C언어] 주사위의 개수 (0) | 2023.08.03 |
---|---|
[프로그래머스/C언어] 팩토리얼 (0) | 2023.08.03 |
[프로그래머스/C언어] 최댓값 만들기 (2) (0) | 2023.08.03 |
[프로그래머스/C언어] 삼각형의 완성조건 (1) (0) | 2023.08.03 |
[프로그래머스/C언어] 암호 해독 (0) | 2023.08.03 |