跪求:C语言的一个基础编程题

来源:百度知道 编辑:UC知道 时间:2024/05/25 05:37:34
帮帮我,我实在是没思路啊,都快疯了!!!!!!
已知在文件in.dat中存有若干个(个数<200)四位数字的正整数,函数readdat()读取这若干个正整数并存入数组xx中。请编制函数calvalue(),其功能要求:(1)、求出这文件中共有多少个正整数totnum;(2)、求出这些数中的各位数字之和是奇数的数的个数totcnt,以及满足此条件的这些数的算术平均值totpjz,最后调用函数writedat()把所求的结果输出。

void calvalue()
{
int i;

totnum = 0;
totcnt = 0;
totpjz = 0;
for (i = 0; i< 200 ; i++)
{
if(xx[i] >0 )
totnum++;
if(((xx[i]%10000)/1000 + (xx[i]%1000)/100 + (xx[i]%100)/10 + (xx[i]%10))%2)
{
totcnt ++;
totpjz += xx[i];
}
}
if(totcnt)
totpjz /= totcnt;

return ;
}

int main(int argc, char* argv[])
{
readdat();
calvalue();
writedat();
return 0;
}