#ifdef LOCAL freopen(\#endif int i;
double H=0; for(i=1;2*i-1<1000000;i++)
{
if(i%2==1)H+=(double)1/(2*i-1); else H-=(double)1/(2*i-1);
}
printf(\return 0;
}
2-8(fin,double)
#include
{
FILE *fin,*fout; fin=fopen(\int n,m,i; double H=0;
double ii; fscanf(fin,\for(i=n;i<=m;i++)
{
ii=(double)i*i; H+=1/ii;
}
fprintf(fout,\
fprintf(fout,\比较 double 和 long long 运行效 率
fclose(fin); fclose(fout); return 0;
}
2-8(fin,long long)
#include
FILE *fin,*fout; fin=fopen(\double H=0;
fscanf(fin,\
{
long long ii=1;// 定义
ii=ii*i*i; // 不用 ii=i*i 也不是 ii*=i*i, 这样做是为了防止 i*i 溢出 ; 可以 认为
这一步将 int 型转化为 long long 型
H+=1/(double)ii;// 不是 (double)1/ii
}
fprintf(fout,\
fprintf(fout,\比较 double 和 long long 运行 效率
{
11 / 15
fclose(fin); fclose(fout); return 0;
}
2-8(freopen)
#include
{
#ifdef LOCAL freopen(\#endif int n,m,i;
double H=0,ii; scanf(\{
H+=1/((double)i*i);
}
printf(\
return 0;
}
2-9(fin)
#include
{
FILE *fin,*fout; fin=fopen(\fscanf(fin,\fclose(fout); return 0;
}
2-9(freopen) #include
{
#ifdef LOCAL freopen(\#endif int a,b,c;
scanf(\
}
2-10(全书看完再看这段代码 ) #include
#include
{
freopen(\
do
{
int a=d[0]*100+d[1]*10+d[2]; int b=d[3]*100+d[4]*10+d[5]; int c=d[6]*100+d[7]*10+d[8];
if(c==3*a&&b==2*a)printf(\}while(next_permutation(d,d+9)); return 0;
}
12 / 15