#include stdio.h
創(chuàng)新互聯(lián)公司云計算的互聯(lián)網(wǎng)服務(wù)提供商,擁有超過13年的服務(wù)器租用、四川雅安電信機房、云服務(wù)器、網(wǎng)絡(luò)空間、網(wǎng)站系統(tǒng)開發(fā)經(jīng)驗,已先后獲得國家工業(yè)和信息化部頒發(fā)的互聯(lián)網(wǎng)數(shù)據(jù)中心業(yè)務(wù)許可證。專業(yè)提供云主機、網(wǎng)絡(luò)空間、域名注冊、VPS主機、云服務(wù)器、香港云服務(wù)器、免備案服務(wù)器等。
int func(int *arr,int n)
{
int i,count=0;
for(i=0;in;i++)
if(arr[i] 0)
count++;
return count;
}
int main()
{
int a[10],i;
for(i=0;i10;i++)
scanf("%d",a[i]);
printf("正整數(shù)的數(shù)量為:%d個\n",func(a,10));
return 0;
}
示例運行結(jié)果:
-1 -2 4 5 6 -9 -8 10 -3 0
正整數(shù)的數(shù)量為:4個
#include?stdio.h
#include?string.h
int?conNumfromStr(char?*,int);
int?main()
{
char?str[21];
printf("輸入20以內(nèi)的字符:");
scanf("%s",str);
printf("字符串中數(shù)字字符個數(shù)為:%d",conNumfromStr(str,strlen(str))?);
return?0;
}
int?conNumfromStr(char?*p,int?len)//計數(shù)字符串中數(shù)字字符的個數(shù)
{
int?i,con=0;
for(i=0;ilen;i++)
{
if(p[i]='0'??p[i]='9')
con++;
}
return?con;
}
使用fopen函數(shù)打開文件,使用fgetc()一個字符一個字符的讀取,然后計數(shù)統(tǒng)計就可以啦,fget()從文件指針stream指向的文件中讀取一個字符,讀取一個字節(jié)后,光標位置后移一個字節(jié),這個函數(shù)的返回值,是返回所讀取的一個字節(jié)。如果讀到文件末尾或者讀取出錯時返回EOF。
#includestdio.h
int main()
{
FILE *fp;
char filename[50];
int num=0;
printf("輸入一個文件名: ");
gets(filename);
if((fp=fopen(filename,"r"))==NULL)
{
printf("文件打開失敗..\n");
return ;
}
while(!feof(fp))fgetc(fp)num++;
printf("%s 文件中共有字符個數(shù): %d\n",filename,num);
fclose(fp);
return ;
}
C語言調(diào)用函數(shù)就是先定義并聲明函數(shù),之后再根據(jù)定義函數(shù)的格式調(diào)用。
下面舉例來說明函數(shù)調(diào)用方法:
#include
int fun(int x, int y); // 函數(shù)聲明,如果函數(shù)寫在被調(diào)用處之前,可以不用聲明
void main()
{
int a=1, b=2, c;
c = fun(a, b); // 函數(shù)的調(diào)用,調(diào)用自定義函數(shù)fun,其中a,b為實際參數(shù),傳遞給被調(diào)用函數(shù)的輸入值
}
// 自定義函數(shù)fun
int fun(int x, int y) // 函數(shù)首部
{ // {}中的語言為函數(shù)體
return xy ? x : y; // 返回x和y中較大的一個數(shù)
}
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兩個函數(shù)的調(diào)用次數(shù)
printf("%d %d", fcnt, scnt);
}
當前名稱:c語言調(diào)用統(tǒng)計函數(shù)介紹 數(shù)值統(tǒng)計的c語言編程
文章起源:http://chinadenli.net/article46/hgcgeg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計、定制開發(fā)、微信公眾號、品牌網(wǎng)站制作、響應(yīng)式網(wǎng)站、網(wǎng)站策劃
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)