68.给定某个字符数组,统计数组中所有英文字符和阿拉伯数字的个数,比如“123fdd”中有英文字符有3个,数字3个。
你好!c语言如下
#include<stdio.h>
void main(){
char a[1000];
int i=0;
int n_engchar=0;//英文字符个数
int n_numchar=0;//阿拉伯数字个数
printf("请输入字符串:\n");
scanf("%s",&a);
while(a[i]!='\0'){
if(a[i]<='9' && a[i]>='0' ) n_numchar+=1;
if(a[i]<='z' && a[i]>='a' || (a[i]<='Z' && a[i]>='A')) n_engchar+=1;
i = i +1;
}
printf("英文字符%d个,阿拉伯数字%d个",n_engchar,n_numchar);
}
char *str = "abc";
int char_count =0;
int num_count = 0;
while(*str) {
if(*str >= ’0‘ && *str <='9') {
num_count++;
} else if((*str>='a' && *str <='z') ||(*str>='A' && *str <='Z')){
char_count++;
}
str++;
}
#include<stdio.h>
int main(void)// x=
{
char test[]={'1','2','3','d','d','d'};
int num_1=0;
int num_2=0;
int i,j,z;
char a[52]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char b[10]={'0','1','2','3','4','5','6','7','8','9'};
for(i=0;i<sizeof(test);i++)
{
for(j=0;j<52;j++)
{
if(test[i]==a[j])
{
num_1++;
}
}
for(z=0;z<10;z++)
{
if(test[i]==b[z])
{
num_2++;
}
}
}
printf("the letter: %d, the number: %d",num_1,num_2);
}
用c函数, isdigit判断是否是数字,isalpha判断是否为字母,在ctype.h文件里面,还有其他判断函数。