问个简单的问题
s=1-1/2+1/3-1/4+1/5……1/i(1/i<1E-6) --------------------编程问答-------------------- 没人啊......................... --------------------编程问答-------------------- 求后续.............. --------------------编程问答-------------------- s=1-1/2+1/3-1/4+1/5……1/i(1/i<1E-6)int i = 1;
int sng = 1;
double s = 0;
while ((double)1 / (double)i < 0.000001)
{
s = s + (double)sng * ((double)1 / (double)i);
sng = 0 - sng;
i++;
} --------------------编程问答--------------------
//与其强制转换不如直接定义成double
double i=1;
double sng=1;
double s=0;
while(1/i<1e-6){
s+=sng*1/i;
sng=-sng;
i++;
}
补充:Java , Eclipse