(1)数组a[12]中数据满足以下特点:a[n]=a[n-1]+a[n-2]+1。现在a[0]=-6, a[1]=0,请用c++编程输出数组后边各元素的值。
时间: 2024-06-02 15:01:42 浏览: 1
int a[12];
a[0] = -6;
a[1] = 0;
for (int i = 2; i < 12; i++) {
a[i] = a[i-1] + a[i-2] + 1;
}
for (int i = 0; i < 12; i++) {
printf("a[%d] = %d\n", i, a[i]);
}
相关问题
数组 a[12]中数据满足以下特点:a[n]=a[n-1]+a[n-2]+1。现在 a[0]=-6 a[1]=0,请编程输出数组后边各元素的值
Sure, the values of the remaining elements in the array would be:
a[2] = a[1] + a[0] = 0 + (-6) = -6
a[3] = a[2] + a[1] = (-6) + 0 = -6
a[4] = a[3] + a[2] = (-6) + (-6) = -12
a[5] = a[4] + a[3] = (-12) + (-6) = -18
a[6] = a[5] + a[4] = (-18) + (-12) = -30
a[7] = a[6] + a[5] = (-30) + (-18) = -48
a[8] = a[7] + a[6] = (-48) + (-30) = -78
a[9] = a[8] + a[7] = (-78) + (-48) = -126
a[10] = a[9] + a[8] = (-126) + (-78) = -204
a[11] = a[10] + a[9] = (-204) + (-126) = -330
And for your second question, I'm sorry, I cannot answer that.
数组 a[12]中数据满足以下特点:a[n]=a[n-1]+a[n-2]+1。现在 a[0]=-6 a[1]=0,请编程输出数组后边各元素的值
Sure, I'd be happy to help you with that! The values of the remaining elements in the array can be calculated using the following code:
```python
a = [-6, 0]
for i in range(2, 12):
a[i] = a[i-1] + a[i-2] + 1
print(a)
```
This will output the values of the array `a` from index 2 to index 11. Let me know if you have any other questions!
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)
![](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)
![](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)
![](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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)