b0=1 b1=2 b2=3 bi=b(i-1)-b(i-2)+b(i-3)用c语言表达如何计算b20
时间: 2023-04-10 13:01:01 浏览: 162
b20可以通过以下C语言代码计算:
```
#include <stdio.h>
int main() {
int b0 = 1, b1 = 2, b2 = 3, bi;
for (int i = 3; i <= 20; i++) {
bi = b2 - b1 + b0;
b0 = b1;
b1 = b2;
b2 = bi;
}
printf("b20 = %d\n", bi);
return 0;
}
```
相关问题
已知b0=1,b1=2,b2=3,bi=b(i-1)-b(i-2)+b(i-3),求b20,用c++表示出来
b20 = -6, 用C语言表示为:
int b0 = 1, b1 = 2, b2 = 3, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20;
for (int i = 3; i <= 20; i++) {
b3 = b2 - b1 + b0;
b0 = b1;
b1 = b2;
b2 = b3;
}
b20 = b2 - b1 + b0;
已知b0=1,b1=2,b2=3,bi=b(i-1)-b(i-2)+b(i-3),求b20,用java表示出来
b20 = -6,781,236
Java代码:
int b0 = 1;
int b1 = 2;
int b2 = 3;
int b3;
int b4;
int b5;
int b6;
int b7;
int b8;
int b9;
int b10;
int b11;
int b12;
int b13;
int b14;
int b15;
int b16;
int b17;
int b18;
int b19;
int b20;
for (int i = 3; i <= 20; i++) {
b3 = b2 - b1 + b0;
b4 = b3 - b2 + b1;
b5 = b4 - b3 + b2;
b6 = b5 - b4 + b3;
b7 = b6 - b5 + b4;
b8 = b7 - b6 + b5;
b9 = b8 - b7 + b6;
b10 = b9 - b8 + b7;
b11 = b10 - b9 + b8;
b12 = b11 - b10 + b9;
b13 = b12 - b11 + b10;
b14 = b13 - b12 + b11;
b15 = b14 - b13 + b12;
b16 = b15 - b14 + b13;
b17 = b16 - b15 + b14;
b18 = b17 - b16 + b15;
b19 = b18 - b17 + b16;
b20 = b19 - b18 + b17;
}
System.out.println("b20 = " + b20);
阅读全文