#include <stdio.h>
#include <sys/timeb.h>
int main(void)
{
struct timeb t1,t2;
long t;
double x, sum=1,suml;
int i,j,n;
printf("Please input the value of x and n:");
scanf("%lf,%d",&x, &n);
ftime(&t1);
for(i=1;i<=n;i++)
{
suml=1;
for(j=1;j<=i;j++)
{
suml=suml*(-1/x);
}
sum+=suml;
}
ftime(&t2);
t=(t2.time-t1.time)*1000+(t2.millitm-t1.millitm);
printf("sum=%lf cost the time %ld",sum,t);
return 0;
}
#include <sys/timeb.h>
int main(void)
{
struct timeb t1,t2;
long t;
double x, sum=1,suml;
int i,j,n;
printf("Please input the value of x and n:");
scanf("%lf,%d",&x, &n);
ftime(&t1);
for(i=1;i<=n;i++)
{
suml=1;
for(j=1;j<=i;j++)
{
suml=suml*(-1/x);
}
sum+=suml;
}
ftime(&t2);
t=(t2.time-t1.time)*1000+(t2.millitm-t1.millitm);
printf("sum=%lf cost the time %ld",sum,t);
return 0;
}