国产18禁黄网站免费观看,99爱在线精品免费观看,粉嫩metart人体欣赏,99久久99精品久久久久久,6080亚洲人久久精品

全國計(jì)算機(jī)等級考試二級C語言上機(jī)題22

時間:2008-10-31 13:41:00   來源:無憂考網(wǎng)     [字體: ]
★題目22
請編寫函數(shù)countvalue(),它的功能是:求n以內(nèi)(不包括n)同時能被3與7整除的所有自然數(shù)之和的平方根s,并作為函數(shù)值返回,最后結(jié)果s輸出到文件out.dat中。
 例如若n為1000時,函數(shù)值應(yīng)為:s=153.909064。
 部分源程序存在文件prog1.c中。
 請勿改動主函數(shù)main()和輸入輸出數(shù)據(jù)函數(shù)progreadwrite()的內(nèi)容。
#include
#include
#include

double countvalue(int n)
{ int i;
 double s=0.0;
 for(i=1;i if(i%21==0) s+=i;
 return sqrt(s);
}

main()
{
 clrscr();
 printf("自然數(shù)之和的平方根=%f\n",countvalue(1000));
 progreadwrite();
}

progreadwrite()
{
 file *fp,*wf;
 int i,n;
 float s;

 fp=fopen("in.dat","r");
 if(fp==null){
 printf("數(shù)據(jù)文件in.dat不存在!");
 return;
 }
 wf=fopen("out.dat","w");
 for(i=0;i<10;i++){
 fscanf(fp,"%d\n",&n);
 s=countvalue(n);
 fprintf(wf,"%f\n",s);
 }
fclose(fp);
fclose(wf);
}