改错题 下列程序功能是:从键盘输入一个字符串,统计其中大写字母个数m和小写字母个数n,并输出m,n中的较大者。 程序如下: #include "stdio. h" #include "string. h int main() { char s[80]; int i,k,m=0,n=0; gets(s); i=1 ; /*$ERROR1$*/ k=strlen(s); while(i<=k) /*$ERROR2$*/ {
时间: 2024-03-08 16:46:15 浏览: 93
有两处错误:
1. 在程序开头需要包含头文件 `stdlib.h`,因为后面使用了 `gets` 函数。
2. 在 `while` 循环中,循环条件应该是 `i < k`,因为字符串的下标是从 0 开始的。
修改后的程序如下:
```
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
int main() {
char s[80];
int i, k, m = 0, n = 0;
gets(s);
k = strlen(s);
for (i = 0; i < k; i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
n++;
} else if (s[i] >= 'A' && s[i] <= 'Z') {
m++;
}
}
printf("%d\n", m > n ? m : n);
return 0;
}
```
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)