问题遇到的现象和发生背景
Write a function, in C or Python, that returns the number of lowercase letters in a chain of characters passed as a parameter. For example, if the chain is Semi-annual, the function must return the number 9.
Write a function, in C or Python, that returns the number of lowercase letters in a chain of characters passed as a parameter. For example, if the chain is Semi-annual, the function must return the number 9.
解答如下
#include <stdio.h>
#include <string.h>
int Count_lowercase_letters(char str[])
{
int count=0,i;
for(i=0;i<strlen(str);i++)
{
if(str[i]<='z'&&str[i]>='a')
{
count++;
}
}
return count;
}
int main()
{
char str[150];
gets(str);
printf("The number of lowercase letters:%d\n",Count_lowercase_letters(str));
return 0;
}