要用Java实现,代码不要太复杂了,就是输入一个x,求这个输入x的sin值。有公式sin(x)=x-x^3/3!+x^5/5!-x^7/7!+x^9/9!-x^11/11!+...(注:x^n表示x的n次方),从键盘输入x,输出相应正弦值,精确到0.000001.
1条回答 默认 最新
- threenewbee 2019-01-10 00:02关注
double a=1, b=1, c=0, x=0,n=0,s=0; Scanner inScanner=new Scanner(System.in); x=inScanner.nextInt(); x = (x*3.1416) / 180; s = x; for (n = 3;; n += 2) { a = a*(n - 1)*n; b = -b; c = Math.pow(x, n) / a; s = s + b*c; if (c <=0.000001) { System.out.println(s); break; } }
解决 无用评论 打赏 举报