aaa
(高顯忠, [email protected], 2012-07-05 14:56)
1樓
#include <cstdlib>
#include <iostream>
using namespace std;
// ----------------------------------------------
#include <math.h>
#include "XXX.h"
// ----------------------------------------------
int main(int argc, char *argv[])
{
double sum, sum_1, sum_2;
int s1, n;
s1= 1;
n= 1;
sum= 0.0;
int ct;
ct= 0;
// for (;;) {
while (1) {
sum+= s1*(1.0/n);
sum_1= sum;
s1*= -1;
n+= 2;
sum+= s1*(1.0/n);
sum_2= sum;
s1*= -1;
n+= 2;
ct++;
if (rel_diff(sum_1, sum_2) < 1.0E-6)
break;
}
printf("%.6lf , %d \n", sum_2, ct);
printf("%.8lf \n", atan(1.0));
system("pause");
return 0;
}
附件
1. XXX.h (1 KB)