c語言輸入一串字符統(tǒng)計個數(shù) C語言編寫函數(shù),統(tǒng)計字符串中數(shù)字字符的個數(shù)?
C語言編寫函數(shù),統(tǒng)計字符串中數(shù)字字符的個數(shù)?#包括和限制。H>#包含<string。H>main(){int i,j=0,K char a[1000]//根據(jù)實際情況自行調(diào)整長度。Prin
C語言編寫函數(shù),統(tǒng)計字符串中數(shù)字字符的個數(shù)?
#包括和限制。H>#包含<string。H>main(){int i,j=0,K char a[1000]//根據(jù)實際情況自行調(diào)整長度。Printf(“請輸入字符串:n”)獲?。╝)k=strlen(a)for(I=0I<ki)if(“0”<=a[I]<=“9”)J Printf(“此字符串中有%d個數(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)//計算字符串{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請輸入一個字符串:n“”
獲取
printf(“字符串中有%d個數(shù)字。n”,countdigit(s))
返回0
}