Kodewick
开始学 →
基础←→0 / 70

电话号码

#043基础字符串条件约 4 分钟

朋友留的电话里夹着横线、空格和括号。写 count_digits(phone),只数 '0' 到 '9' 的字符有几个,别的都不算。空字符串返回 0。

示例
count_digits("138-0013-8000")→11
count_digits("")→0
函数int count_digits(const char *phone)
main.c
int count_digits(const char *phone) {
    int n = 0;
    for (int i = 0; phone[i] != '\0'; i++) {
        // 在这里写:是 '0' 到 '9' 之间的字符,n 就加 1
    }
    return n;
}
Ctrl + Enter 也能运行
结果

写好了先点「运行」试试示例,没问题再点「提交」。