43、请编写函数countvalue(),它的功能是:求n以内(不包括n)同时能被3和7整数的
double countvalue(int n)
{
}
main()
{
clrscr();
printf("s=%f\n",countvalue(1000));
progreadwrite();
}
progreadwrite()
{
FILE *fp,*wf;
int i,n;
float s;
fp=fopen("in.dat","r");
if(fp==NULL)
{printf("Can't open the data file in.dat\007\n");
return;
}
wf=fopen("out.dat","w");
for(i=0;i<10;i++)
{fscanf(fp,"%d",&n);
s=countvalue(n);
fprintf(wf,"%f\n",s);
}
fclose(fp);
fclose(wf);
}
/* 注:由于能同时被3和7整除的自然数最小的是21,而它们之间的间隔应是21(由最小
公倍数可得)。因而在for()循环可定成如下形式。*/
double countvalue(int n)
{
int i;
float s=0.0;
for(i=21;i<n;i+=21)
s+=i;
s=sqrt(s);
return s;
}