二级C语言 程序设计题

按题目要求编写完整功能代码,参考答案点击按钮展开

81程序设计题:统计大写字母个数

编写函数 countupper,统计字符串 s 中大写字母('A'..'Z')的个数。只在函数体内编写。

#include <stdio.h>
int countupper(char *s)
{
    // 请在此处编写函数体
}
int main()
{
    printf("%d\n", countupper("AbCdeFG"));
    return 0;
}
参考答案
int countupper(char *s)
{
int c = 0;
while(*s){
if(*s >= 'A' && *s <= 'Z') c++;
s++;
}
return c;
}
解析

遍历每个字符,判断是否在 'A'..'Z' 范围内,是则计数加 1。countupper("AbCdeFG") 输出 4。

试题及答案仅供练习参考,不保证完全准确,正式考试请以NCRE官方教材及官方内容为准。

©2026 NCRE二级题库 版权所有