java编写程序,用while循环100以内-1+1/2-1/3+1/4-……-1/99+1/100
int a=1;
double s;
while(true){
if(a==100)
break;
if(a%2==1){
s=s+1/(-a);
}else{
s=s+1/a;
}
a=a+1;
}
这样不知错不错
我试试
本回答被网友采纳java编写程序,用for循环100以内-1+1\/2-1\/3+1\/4-……-1\/99+1\/100
if(i % 2 == 0){ sum += 1\/i;}else { sum -= 1\/i;} } 没有编译器,你回去就按这个思路写吧,写一个1-100的循环,如果i和2取模,为0的时候就是+,不为0的时候就是-。然后用 +=。 你写成sum = sum +1\/i. sum = sum-1\/i 都行 ...
编写一个Java程序,计算并输出算式1-1\/2+1\/3-1\/4+...+1\/99-1\/100 的...
public class T {public static void main(String[] args) {double a = 1.0;\/\/ 接收最后结果double sum = 0.0; \/\/ 循环 i的值从1-100for (int i = 1; i <= 100; i++) {\/\/ 观察算式,分母是偶数时,分数为负if(i%2 == 0)sum += -(a\/i);elsesum += (a\/i);}System...
vb试题编程计算1-1\/2+1\/3-1\/4+...+1\/99-1\/100的四种方法是什么?
1:\\x0d\\x0aDim i As Integer\\x0d\\x0aDim s As Double\\x0d\\x0aDim s0 As Double\\x0d\\x0aFor i = 1 To 100\\x0d\\x0as0 = 1 \/ i\\x0d\\x0aIf i Mod 2 = 0 Then s0 = s0 * (-1)\\x0d\\x0as = s + s0\\x0d\\x0aNext\\x0d\\x0aPrint s\\x0d\\x0a\\x0d\\...
利用循环编程计算并输出表达式S=1-1\/2+1\/3-1\/4……+1\/99-1\/100值
Private Sub Command1_Click()Dim sum As Doublesum = 0For i = 1 To 100 sum = sum + ((-1) ^ (i + 1)) \/ iNext iPrint sumEnd Sub
编程“计算1-1\/2+1\/3-1\/4+...+1\/99-1\/100+...直到最后一项的绝对值小...
include "stdio.h"main(){ float sum=0,i=1,j,t=1;do {j=t\/i;i++;t=-t;sum+= j;}while (i<=10000);printf("1-1\/2+1\/3-1\/4+ ... +-1\/%.0f = %lf",i, sum);}
编写一个程序求1-1\/2+1\/3-1\/4+…+1\/99-1\/100的值。
include <stdio.h> main(){ int i,k=1;float , sum=0;for(i=1;i<=100;i++){ sum+=k*1.0\/i;k=-k;} printf("sum=%f\\n",sum);}
2.编程,求下列式子的值:y=1-1\/2+1\/3-1\/4+.+1\/99-1\/100并将结果输出...
include <stdio.h> int main() { int i;double y = 0;for (i = 1; i <= 100; ++i) { if (i % 2 == 1) { y += 1.0 \/ i;} else { y -= 1.0 \/ i;} } printf("y = %f\\n", y);return 0;} 输出结果:y = 0.688172 ...
...1-1\/2+1\/3-1\/4++1\/(99)-1\/(100) ,用伪代码表示?
sum = 1 sign = -1 for i = 2 to 100 do:sign = -1 * sign sum = sum + (sign * 1 \/ i)print sum
编写程序求1-1\/2+1\/3-1\/4……+1\/99-1\/100的值
function box(n) { if (n < 1 || n > 100) { return "error" } var result = 0; for (var i = 1; i <= n; i++) { if (i % 2 == 0) { result -= 1\/i; } else { result += 1\/i; } } return result;}console.log(box(100))
用raptor 计算 1-1\/2+1\/3-1\/4+1\/5-1\/6...+1\/99-1\/100
1、按照计算逻辑,摆出计算用的流程图,如下图所示:2、设置参数,点击赋值框1,选择编辑,在赋值框1是set栏输入sum,to栏输入0。意思是将0赋值给sum。3、同理,在赋值框2set栏输入 i ,to栏输入 1;在赋值框3set栏输入 sum, to栏输入 sum-1\/i;在赋值框4set栏输入 sum ,to栏输入 sum+...