编了一个循环的小程序....当过大时运行缓慢,而且出错了求改正.N>=40000
#include<stdio.h>#include<stdlib.h>
#define M 100
void main()
{
double x,y,f,sum,a[M],b[M],c[M],d[M];
int i,j,n,t=0;
char ch;
do
{
sum=0;f=0;
printf("please input N (N<=100000):\n");
scanf("%d",&n);
for(i=1;i<(n+1);i++)
for(j=1;j<(n+1);j++)
{
x=1.0*i/n;
y=1.0*j/n;
f=x*y/(n*n);
sum=sum+f;
}
t=t+1;
a[t]=sum;
b[t]=n;
printf("When the N is %d,the sum is %.10lf\n",n,sum);
fflush(stdin);
printf("Again? Y/N\n");
ch=getchar();
}while((ch=='y')||(ch=='Y'));
a[0]=0;b[0]=0;
for(i=1;i<=t;i++)
{
c[i]=a[i]-a[i-1];
d[i]=b[i]-b[i-1];
}
for(i=1;i<=t;i++)
printf("%10.2lf %10.10lf %10.2lf %10.10lf\n",b[i],a[i],d[i],c[i]);
system("PAUSE");
}