#include<stdio.h>
int main()
{
int i = 0;
double num = 0.0;
int flag = 1;
for (i = 1; i <= 100; i++)
{
num += (1.0 / i)*flag;
flag = -flag;
}
printf("%lf", num);
system("pause");
return 0;
}
时间: 2024-10-12 20:28:29
#include<stdio.h>
int main()
{
int i = 0;
double num = 0.0;
int flag = 1;
for (i = 1; i <= 100; i++)
{
num += (1.0 / i)*flag;
flag = -flag;
}
printf("%lf", num);
system("pause");
return 0;
}