求1/1-1/2+1/3-1/4…..1/100的和 // 聲明變數 var a = 1; var sum1 = 0; var sum2 = 0; while(a <= 100){ if(a % 2 == 0){ sum1 =sum1 - (1 / a); }else{ sum2 =sum2 + ( ...
求1/1-1/2+1/3-1/4…..1/100的和
// 聲明變數 var a = 1; var sum1 = 0; var sum2 = 0; while(a <= 100){ if(a % 2 == 0){ sum1 =sum1 - (1 / a); }else{ sum2 =sum2 + (1 / a); } a++; } // 將結果列印到控制台 console.log(sum1+sum2);