#includestdio.h

創(chuàng)新互聯(lián)建站長(zhǎng)期為超過(guò)千家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開(kāi)放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為博望企業(yè)提供專業(yè)的成都網(wǎng)站建設(shè)、成都做網(wǎng)站,博望網(wǎng)站改版等技術(shù)服務(wù)。擁有十多年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開(kāi)發(fā)。
#define N 100
void count(char str[],int times[]) //統(tǒng)計(jì)小寫(xiě)字符出現(xiàn)次數(shù)
{
int i;
for(i=0;str[i]!='\0';i++)
{
if(str[i]='a' str[i]'a'+26) //只統(tǒng)計(jì)小寫(xiě)字符
times[str[i]-97]++; //字符a的ascii碼為97,str[i]-97正好將26個(gè)字母對(duì)應(yīng)在times數(shù)組的26個(gè)位置上。
}
}
int main()
{
char str[N];
int i,times[26]; //time數(shù)組中每一個(gè)元素代表一個(gè)小寫(xiě)字符,其值代表字符的出現(xiàn)次數(shù)
for(i=0;i26;i++) //初始化,所有字符次數(shù)置0
times[i]=0;
scanf("%s",str); //讀入字符串
count(str,times); //調(diào)用函數(shù)統(tǒng)計(jì)次數(shù),讓times裝載統(tǒng)計(jì)結(jié)果
for(i=0;i26;i++) //輸出結(jié)果,小寫(xiě)字符a的ascii碼為97.
{
printf("%c\t%d\n",i+97,times[i]);
}
return 0;
}
void f(int* k, int n, int* fcnt, int* scnt)
{
void s(int* k, int n, int* fcnt, int* scnt);
++*fcnt;
++* k;
if (*k == n)
return;
s(k, n, fcnt, scnt);
}
void s(int* k, int n, int* fcnt, int* scnt)
{
void f(int* k, int n, int* fcnt, int* scnt);
++*scnt;
++*k;
if (*k == n)
return;
f(k, n, fcnt, scnt);
}
void solve(int n)
{
void f(int* k, int n, int* fcnt, int* scnt);
int k = 0, fcnt = 0, scnt = 0;
f(k, n, fcnt, scnt);
//輸出f與s兩個(gè)函數(shù)的調(diào)用次數(shù)
printf("%d %d", fcnt, scnt);
}
傳遞一個(gè)指針進(jìn)函數(shù),用指針來(lái)記錄
如:
#includestdio.h
int
call(int
*p)
{
(*p)++;
return
0;
}
int
main()
{
int
a=0;
int
*p=a;
call(p);
//調(diào)用1次
call(p);
//調(diào)用2次
printf("call函數(shù)調(diào)用次數(shù):%d\n",a);
}
#include stdio.h
int count(char* s, char x);
int main()
{
char s[80], x;
gets(s);
scanf("\n%c", x);
printf("%d", count(s, x));
}
int count(char* s, char x)
{
static int n = 0;
if (*s)
{
? if (*s == x)
? ? ? n++;
? count(s + 1, x);
}
return n;
}
網(wǎng)站名稱:c語(yǔ)言次數(shù)函數(shù),c語(yǔ)言統(tǒng)計(jì)數(shù)字出現(xiàn)的次數(shù)
文章地址:http://chinadenli.net/article26/dsippcg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供、全網(wǎng)營(yíng)銷(xiāo)推廣、用戶體驗(yàn)、網(wǎng)站內(nèi)鏈、網(wǎng)站改版、網(wǎng)站導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)