按题目要求编写完整功能代码,参考答案点击按钮展开
编写函数 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。