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