C编程编写一个函数,统计 array 数组中小写字母的个数并
返回。
第1个回答 2012-01-08
看来是编写子函数的题目了
最好能声明一个头文件#include<ctype.h>
这样就可以用函数islower了,这个函数是用来判断字符是否是小写字母,是则返回1,否则返回0;
如果已经声明这个头函数,那么代码如下:
int islower(char array[])
{
int n=0;
char *p;
p=array;
while(*p++)
{
if(islower(*p))
n++;
}
return n;
}
如果没有声明ctype.h,那么就把islower(*p)改成:'a'<=*p&&*p<='z'即可。
最好能声明一个头文件#include<ctype.h>
这样就可以用函数islower了,这个函数是用来判断字符是否是小写字母,是则返回1,否则返回0;
如果已经声明这个头函数,那么代码如下:
int islower(char array[])
{
int n=0;
char *p;
p=array;
while(*p++)
{
if(islower(*p))
n++;
}
return n;
}
如果没有声明ctype.h,那么就把islower(*p)改成:'a'<=*p&&*p<='z'即可。
第2个回答 2012-01-08
#include<stdio.h>
int lower(char A[])
{
int i,count=0;
for(i=0; A[i]; i++)
{
if(islower(A[i])) count++;
}
return count;
}
int main()
{
char array[]="AALlnsh97t87";
int n=lower(array);
printf("%d\n",n);
return 0;
}追问
int lower(char A[])
{
int i,count=0;
for(i=0; A[i]; i++)
{
if(islower(A[i])) count++;
}
return count;
}
int main()
{
char array[]="AALlnsh97t87";
int n=lower(array);
printf("%d\n",n);
return 0;
}追问
程序错误无法运行
追答我运行过了。
你用什么编绎器?
想起来了,,
加个头文件 #include
我的编绎器默认了头文件
第3个回答 2012-01-08
#include <stdio.h>
void main(){
int count=0;
char array[10];
scanf("%s",&array);
for(int i=0;i<10;i++)
if(array[i]>='a'&&array[i]<='z')
count++;
printf("小写字母的个数为:%d\n",count);
}
void main(){
int count=0;
char array[10];
scanf("%s",&array);
for(int i=0;i<10;i++)
if(array[i]>='a'&&array[i]<='z')
count++;
printf("小写字母的个数为:%d\n",count);
}