我想在A1细胞上写下Fibonacci序列的前20个值 输出应为1,1,2,3,5,8,13,21,34,55
我在尝试将数字添加到字符串时出错。
如何将结果放入A1单元格?
这是我的尝试:
<ion-header>
<ion-navbar>
<ion-title>Home</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-list inset>
<button ion-item *ngFor="let item of items" (click)="itemSelected(item)">
<p>{{ item.id }} <span ng-bind="item.text"></span></p>
</button>
</ion-list>
</ion-content>
答案 0 :(得分:3)
Sub Looping()
series = "1"
oldvar = 1
newvar = 1
For x = 1 To 20
series = Series & "," & newvar
newvar = oldvar + newvar
oldvar = newvar - oldvar
Next x
cells(1,1) = series
End Sub
答案 1 :(得分:2)
使用数组非常不同,因此可以根据需要输出数组。
Sub Looping()
Dim a(19) As Long
Dim sOut As String
Dim newvar As Long
series=1
newvar = 1
For x = 1 To 20
If x > 2 Then
newvar = a(x - 3) + a(x - 2)
a(x - 1) = newvar
Else
a(x - 1) = series
End If
sOut = sOut & IIf(x > 1, ",", "") & CStr(newvar)
Next x
Range("a1").Value = sOut
End Sub