π/4=1−1/3+1/5−1/7+⋯+14n−3−1/4n−1 (1)n取1000时计算π的近似值。 (2)求π的近似值,直到最后一项的绝对值小于 ⁻⁶ 10⁻⁶
时间: 2023-10-04 10:03:01 浏览: 65
(1)根据公式,当n=1000时,π的近似值为:
π/4 = 1 - 1/3 + 1/5 - 1/7 + ... + (-1)^(1000+1) / (4*1000-3) - 1 / (4*1000-1)
π ≈ 4 * (1 - 1/3 + 1/5 - 1/7 + ... + (-1)^(1000+1) / (4*1000-3) - 1 / (4*1000-1))
使用计算器计算上式得到:
π ≈ 3.1405926538
(2)根据公式,当最后一项的绝对值小于 10^(-6) 时,π的近似值为:
π/4 = 1 - 1/3 + 1/5 - 1/7 + ... + (-1)^n / (4n-3) - 1 / (4n-1)
要使最后一项的绝对值小于 10^(-6),即:
1 / (4n-1) < 10^(-6)
解得 n > 250000.25,因此 n 取 250001 时,最后一项的绝对值小于 10^(-6)。代入公式计算得到:
π ≈ 3.1415916536
相关问题
一个算法的时间复杂度为(n^3+n^2log2n+14n)/n^2,其数量级表示为____
一个算法的时间复杂度为(n^3+n^2log2n+14n)/n^2,其数量级表示为O(n^2logn)。因为当n趋近于无穷大时,算法的时间复杂度主要由n的二次方项和n的二次方项与logn的乘积项决定,而n的二次方项与logn的乘积项增长速度比n的二次方项慢,因此可以将其忽略,从而得到O(n^2logn)的时间复杂度。
跨年倒计时html代码圣诞树
以下是HTML+CSS+JS实现跨年倒计时和绘制精美彩色闪灯圣诞树的代码:
1. 跨年倒计时HTML代码:
```html
<div id="countdown">
<div>
<span id="days"></span>
<div class="smalltext">Days</div>
</div>
<div>
<span id="hours"></span>
<div class="smalltext">Hours</div>
</div>
<div>
<span id="minutes"></span>
<div class="smalltext">Minutes</div>
</div>
<div>
<span id="seconds"></span>
<div class="smalltext">Seconds</div>
</div>
</div>
```
2. 跨年倒计时CSS代码:
```css
#countdown {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
#countdown > div {
display: inline-block;
margin-right: 20px;
}
#countdown span {
display: block;
font-size: 50px;
color: #fff;
text-shadow: 2px 2px 5px #000;
}
.smalltext {
color: #fff;
text-shadow: 2px 2px 5px #000;
}
```
3. 跨年倒计时JS代码:
```javascript
function countdown() {
var now = new Date();
var eventDate = new Date(2022, 0, 1);
var currentTime = now.getTime();
var eventTime = eventDate.getTime();
var remTime = eventTime - currentTime;
var s = Math.floor(remTime / 1000);
var m = Math.floor(s / 60);
var h = Math.floor(m / 60);
var d = Math.floor(h / 24);
h %= 24;
m %= 60;
s %= 60;
h = (h < 10) ? "0" + h : h;
m = (m < 10) ? "0" + m : m;
s = (s < 10) ? "0" + s : s;
document.getElementById("days").textContent = d;
document.getElementById("hours").textContent = h;
document.getElementById("minutes").textContent = m;
document.getElementById("seconds").textContent = s;
setTimeout(countdown, 1000);
}
countdown();
```
4. 绘制精美彩色闪灯圣诞树HTML+CSS+SVG代码:
```html
<div class="tree">
<div class="tree-top"></div>
<div class="tree-body">
<div class="tree-layer"></div>
<div class="tree-layer"></div>
<div class="tree-layer"></div>
<div class="tree-layer"></div>
<div class="tree-layer"></div>
<div class="tree-layer"></div>
<div class="tree-layer"></div>
<div class="tree-layer"></div>
<div class="tree-layer"></div>
<div class="tree-layer"></div>
</div>
</div>
```
```css
.tree {
position: relative;
width: 0;
height: 0;
margin: 0 auto;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 100px solid green;
}
.tree-top {
position: absolute;
top: -50px;
left: -50px;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 50px solid green;
}
.tree-body {
position: absolute;
top: 0;
left: -50px;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 50px solid green;
}
.tree-layer {
position: relative;
width: 0;
height: 0;
margin: 0 auto;
border-left: 45px solid transparent;
border-right: 45px solid transparent;
border-bottom: 40px solid red;
transform: translateY(-30px);
}
.tree-layer:nth-child(2n) {
border-bottom-color: yellow;
}
.tree-layer:nth-child(3n) {
border-bottom-color: blue;
}
.tree-layer:nth-child(4n) {
border-bottom-color: purple;
}
.tree-layer:nth-child(5n) {
border-bottom-color: orange;
}
.tree-layer:nth-child(6n) {
border-bottom-color: pink;
}
.tree-layer:nth-child(7n) {
border-bottom-color: brown;
}
.tree-layer:nth-child(8n) {
border-bottom-color: gray;
}
.tree-layer:nth-child(9n) {
border-bottom-color: gold;
}
.tree-layer:nth-child(10n) {
border-bottom-color: silver;
}
.tree-layer:nth-child(11n) {
border-bottom-color: black;
}
.tree-layer:nth-child(12n) {
border-bottom-color: white;
}
.tree-layer:nth-child(13n) {
border-bottom-color: cyan;
}
.tree-layer:nth-child(14n) {
border-bottom-color: magenta;
}
.tree-layer:nth-child(15n) {
border-bottom-color: lime;
}
.tree-layer:nth-child(16n) {
border-bottom-color: teal;
}
.tree-layer:nth-child(17n) {
border-bottom-color: navy;
}
.tree-layer:nth-child(18n) {
border-bottom-color: olive;
}
.tree-layer:nth-child(19n) {
border-bottom-color: maroon;
}
.tree-layer:nth-child(20n) {
border-bottom-color: fuchsia;
}
```
5. 绘制精美彩色闪灯圣诞树JS代码:
```javascript
var tree = document.querySelector('.tree');
var lights = document.createElement('div');
lights.classList.add('lights');
tree.appendChild(lights);
for (var i = 0; i < 50; i++) {
var light = document.createElement('div');
light.classList.add('light');
light.style.animationDelay = Math.random() * 10 + 's';
lights.appendChild(light);
}
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)