The prototype of the function count is: int count(char *s);, its function is to count the number of all lowercase English letters in the string s. The main function for testing is shown below, please create the function count.

The prototype of the function count is: int count(char *s);, its function is to count the number of all lowercase English letters in the string s. The main function for testing is shown below, please create the function count.

#include<stdio.h>
int main()
{
    
    
int count(char *s);
char str[200];
int slen;
gets(str);
slen=count(str);
printf(“count=%d\n”,slen);
return 0;
}

The complete code is as follows:

#include<stdio.h>
#include <string.h>

int count(char *s)
{
    
    
	int i,n=0;
	for(i=0;i<=strlen(s);i++)
	{
    
    
	if(*(s+i)>='a'&&*(s+i)<='z')
		n++;
	}
	return n;
}

int main()
{
    
    
	int count(char *s);
    char arr[200];
    int len;
    gets(arr);
    len=count(arr);
    printf("其中小写字母有%d个\n",len);
    return 0;
}

The result of the operation is shown in the figure:
Insert picture description here
Caicai's code, I hope it can help you!

Guess you like

Origin blog.csdn.net/Sconnie/article/details/114086188