c語(yǔ)言輸入一串字符統(tǒng)計(jì)個(gè)數(shù) C語(yǔ)言編寫函數(shù),統(tǒng)計(jì)字符串中數(shù)字字符的個(gè)數(shù)?
C語(yǔ)言編寫函數(shù),統(tǒng)計(jì)字符串中數(shù)字字符的個(gè)數(shù)?#包括和限制。H>#包含<string。H>main(){int i,j=0,K char a[1000]//根據(jù)實(shí)際情況自行調(diào)整長(zhǎng)度。Prin
C語(yǔ)言編寫函數(shù),統(tǒng)計(jì)字符串中數(shù)字字符的個(gè)數(shù)?
#包括和限制。H>#包含<string。H>main(){int i,j=0,K char a[1000]//根據(jù)實(shí)際情況自行調(diào)整長(zhǎng)度。Printf(“請(qǐng)輸入字符串:n”)獲取(a)k=strlen(a)for(I=0I<ki)if(“0”<=a[I]<=“9”)J Printf(“此字符串中有%d個(gè)數(shù)字字符!N“,J)}
~]#包括<stdio。H>#包含<string。H>int connumfromstr(char*,int)int main(){char STR[21]printf(“enter characters within 20:”)scanf(“%s”,STR)printf(“字符串中的數(shù)字字符數(shù)為%d”,connumfromstr(STR,strlen(STR)))return 0}int connumfromstr(char*P,int))Len)//計(jì)算字符串{int i中的數(shù)字字符數(shù),con=0表示(I=0I<leni){if(P[I]>=“0”&&P[I]<=“9”)con}return con}
~]include
35; include
int countdigit(char*P)
{int n=0
表示(*PP)
if(isDigit(*P))n
return n
}]int main()
{char s[300
]printf請(qǐng)輸入一個(gè)字符串:n“”
獲取
printf(“字符串中有%d個(gè)數(shù)字。n”,countdigit(s))
返回0
}