#includestdio.h

創新互聯公司專注于企業營銷型網站建設、網站重做改版、洪江網站定制設計、自適應品牌網站建設、H5場景定制、商城建設、集團公司官網建設、成都外貿網站建設、高端網站制作、響應式網頁設計等建站業務,價格優惠性價比高,為洪江等各大城市提供網站開發制作服務。
#includestring.h
main()
{
int?i,j=0,k;
char?a[1000];//長度自己根據實際情況調整
printf("請輸入一串字符串:\n");
gets(a);
k=strlen(a);
for(i=0;ik;i++)
if('0'=a[i]='9')
j++;
printf("這串字符串中數字字符有%d個!\n",j);
}
#include "stdio.h"
#include "stdlib.h"
int getCharCount(char *sz,char ch,int len)
{
int i = 0;
int icount =0;
for(i=0;ilen,i++)
{
if(*sz == ch)
icount = icount +1;
sz++;
}
return icount;
}
void main()
{
char sz[10]={'a','b','c','a','a','d','b','a','c','a'};
int iCnt=0;
iCnt = getCharCount(sz,'a',10);
printf("a 的個數為 %d",iCnt);
getche();
}
輸入一行字符分別統計,出其中英文字母空格數字和其他字符的個數的源代碼如下:
#includestdio.h
int main()
{
char c;
int letters=0,spaces=0,digits=0,others=0;
printf("請輸入一些字母:\n");
while((c=getchar())!='\n')
{
if((c='a'c='z')||(c='A'c='Z'))
letters++;
else if(c='0'c='9')
digits++;
else if(c==' ')
spaces++;
else
others++;
}
printf("字母=%d,數字=%d,空格=%d,其他=%d\n",letters,digits,spaces,others);
return 0;
}
擴展資料
C語言程序統計一個文件的字符數的源代碼如下
#include stdio.h
#include stdlib.h
int main(void)
{
int counter = 0; //計數器
int ch; //存儲從文件中讀入的字符
while( EOF != (ch = getchar()) ) //使用getchar函數從標準輸入中讀取字符,當讀取到末尾時停止循環
{
counter++; //計數器自增
}
printf("%d", counter);
return 0;
}
文章名稱:c語言源代碼統計函數個數 c語言數據統計
網站網址:http://www.yijiale78.com/article46/ddgsoeg.html
成都網站建設公司_創新互聯,為您提供域名注冊、網站內鏈、面包屑導航、企業網站制作、網站策劃、微信公眾號
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯