b0=1 b1=2 b2=3 bi=b(i-1)-b(i-2)+b(i-3)用c语言表达如何计算b20
时间: 2023-04-10 15:01:01 浏览: 157
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表示出来
根据题目中给出的递推式,可以得到b3=b2-b1-b0=-1,b4=b3-b2-b1=-4,b5=b4-b3-b2=-2,b6=b5-b4-b3=3,b7=b6-b5-b4=9,b8=b7-b6-b5=-10,b9=b8-b7-b6=-2,b10=b9-b8-b7=19,b11=b10-b9-b8=-33,b12=b11-b10-b9=52,b13=b12-b11-b10=-100,b14=b13-b12-b11=185,b15=b14-b13-b12=-337,b16=b15-b14-b13=622,b17=b16-b15-b14=-1155,b18=b17-b16-b15=2132,b19=b18-b17-b16=-3937,b20=b19-b18-b17=7250。因此,b20=7250,用C表示为:int b20 = 7250;
已知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);
阅读全文