本题目要求读入不含空格的字符串,然后输出这个字符串中小写字母的个数。
时间: 2023-05-24 21:06:06 浏览: 172
#include <stdio.h>
int main()
{
char str[100];
int i, count=0;
scanf("%s", str); //输入字符串
for(i=0; str[i]!='\0'; i++)
{
if(str[i]>='a' && str[i]<='z') //判断是否为小写字母
count++; //累加小写字母个数
}
printf("%d\n", count); //输出结果
return 0;
}
相关问题
本题目要求读入不含空格的字符串,然后输出这个字符串中小写字母的个数
思路:
1. 读入字符串
2. 遍历字符串中每一个字符,如果是小写字母,则计数器加1
3. 输出计数器的值
Python代码:
```python
s = input() # 读入字符串
count = 0 # 初始化计数器
for c in s: # 遍历字符串中每个字符
if c.islower(): # 如果字符是小写字母
count += 1 # 计数器加1
print(count) # 输出计数器的值
```
C++代码:
```cpp
#include <iostream>
using namespace std;
int main() {
string s;
cin >> s;
int count = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] >= 'a' && s[i] <= 'z') {
count++;
}
}
cout << count << endl;
return 0;
}
```
C语言本题目要求读入不含空格的字符串,然后输出这个字符串中小写字母的个数
。实现思路:
1. 读入不含空格的字符串;
2. 遍历字符串,判断每个字符是否为小写字母;
3. 如果是小写字母,计数器加1;
4. 输出计数器的值。
代码如下:
```c
#include <stdio.h>
int main() {
char str[100];
int count = 0;
printf("请输入一个不含空格的字符串:");
scanf("%s", str);
for (int i = 0; str[i] != '\0'; i++) {
if (str[i] >= 'a' && str[i] <= 'z') {
count++;
}
}
printf("小写字母的个数为:%d\n", count);
return 0;
}
```
阅读全文
相关推荐












