问答题
请编写函数countValue(),它的功能是:求n以内(不包括n)同时能被3与7整除的所有自然数之和的平方根s,并作为函数值返回,最后结果s输出到文件OUT11.DAT中。
例如,若n为1000时,函数值应为s=153.909064。
注意:部分源程序已给出。
请勿改动主函数main()和输入输出函数progReadWrite()的内容。
试题程序:
#include<conio.h>
#include<math.h>
#include<stdio.h>
double countValue(int n)
main ( )
clrscr();
printf ("自然数之和的平方根=%f\n", countValue(lO00)) ;
pregReadWrite();
pregReadWrite()
FILE *wf;
int i, n;
float s;
wf = fepen("OUT11.DAT", "w");
s = ceuntValue(1000);
fprintf(wf, "%f\n", s);
fclese(wf);
【参考答案】
double countValue(int n)
{
double xy=0.0;......
(↓↓↓ 点击下方‘点击查看答案’看完整答案、解析 ↓↓↓)