用VB编程:有一个数列第一项为0,第二项为1,从第三项起,每项均为他的前两项之和,编程输出该数列的前40项
展开全部
这种计算逻辑性、顺序性很强的。
Private Sub Form_Click()
Dim a As Long, b As Long, c As Long
a = 0: b = 1: c = 1
Print a; b; c
For i = 0 To 36
Select Case i Mod 3
Case 0
a = b + c
Print a;
Case 1
b = a + c
Print b;
Case 2
c = a + b
Print c
End Select
Next
End Sub
Private Sub Form_Click()
Dim a As Long, b As Long, c As Long
a = 0: b = 1: c = 1
Print a; b; c
For i = 0 To 36
Select Case i Mod 3
Case 0
a = b + c
Print a;
Case 1
b = a + c
Print b;
Case 2
c = a + b
Print c
End Select
Next
End Sub
追问
复制过去之后运行不了,它说是i未声明,又说字符无效什么的,为什么会这样呢?
追答
我复制过来完全可以的,如果不行,你就给i声明一下。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
VC行么,写个凑合看呗
#include<stdio.h>
int main(void)
{
int a=0,b=1,c=0,i;
printf("%d\n", a);
for (i=0; i<40; i++)
{
printf("%d\n", b);
c=b;
b=a+b;
a=c;
}
return 0;
}
#include<stdio.h>
int main(void)
{
int a=0,b=1,c=0,i;
printf("%d\n", a);
for (i=0; i<40; i++)
{
printf("%d\n", b);
c=b;
b=a+b;
a=c;
}
return 0;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用数组吧。
dim i as long
dim ar(1 to 40) as long
ar(1) =0
ar(2) = 1
for i = 3 to 40
ar(i) = ar(i - 1) + ar(i - 2)
next
for i = 1 to 40
print ar(i)
next
dim i as long
dim ar(1 to 40) as long
ar(1) =0
ar(2) = 1
for i = 3 to 40
ar(i) = ar(i - 1) + ar(i - 2)
next
for i = 1 to 40
print ar(i)
next
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
a = 0
Print a
b = 1
For i = 2 To 40
Print b
b = a + b
a = b - a
Next
End Sub
a = 0
Print a
b = 1
For i = 2 To 40
Print b
b = a + b
a = b - a
Next
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询