关于三级上机的一道题! 急!

来源:百度知道 编辑:UC知道 时间:2024/05/30 19:18:00
原题是这样
请编写函数countvalue(),它的功能是:求n以内(不包括n)同时能被3和7整数的所有自然数之和的平方根s,并作为函数值返回,最后结果s输出到文件out.dat中。
例如若n为1000时,函数值应为:s=153.909064。
注意:部分源程序已给出。
请勿改动主函数main()和输入输出数据函数progreadwrite()的内容。

答案是
double countValue(int n)
{ double xy = 0.0;
int i;
for (i=1; i<n; i++)
if (i%3==0 && i%7==0)
xy += i;
xy = sqrt((double)xy);
return xy;
}
题上的源程序是
#include <conio.h>
#include <math.h>
#include <stdio.h>
double CountValue(int n)
{

}
void progReadWrite()
{ FILE *fp, *wf;
int i, n;
float s;
fp = fopen("in.dat", "r");
if (fp == NULL)
{ printf("数据文件in.dat不存在!");
return;
}
wf = fopen("out.dat", "w");
for (i=0; i<10; i++)
{ fscanf(fp, "%d,", &n);
s = (float)countValue(n);
fprintf(wf, "%f\n", s);

答案就是你写的函数名countValue和题目给的CountValue不一样,至于具体实现,没细看

s = (float)countValue(n);

函数调用的过程中函数名写错了。

其他的调试没有错误。。。