问答题

请编写函数countValue(),它的功能是:求n以内(不包括n)同时能被3与7整除的所有自然数之和的平方根s,并作为函数值返回,最后结果s输出到文件OUT11.DAT中。 例如,若n为1000时,函数值应为s=153.909064。 注意:部分源程序已给出。 请勿改动主函数main()和输入输出函数progReadWrite()的内容。 试题程序: #include #include #include double countValue(int n) { } main() { clrscr(); printf("自然数之和的平方根=%f\n", countValue(1000)); progReadWrite(); } progReadWrite() { FILE *wf; int i, n; float s; wf = fopen("OUT11.DAT", "w"); s = countValue(1000); fprintf(wf, "%f\n", s); fclose(wf); }

【参考答案】

double countValue(int n){ double xy=0.0;int i;for(i=1;i
(↓↓↓ 点击下方‘点击查看答案’看完整答案、解析 ↓↓↓)