螺旋数列多种版本
更新时间:2024-06-21 10:09:01 阅读量: 综合文库 文档下载
- 斐波那契螺旋数列推荐度:
- 相关推荐
用VB写出螺旋数字打印的代码:
代码实现在窗体上打印如下列文字的效果:
01 02 03 04 05 06 07 08 09 10
36 37 38 39 40 41 42 43 44 11
35 64 65 66 67 68 69 70 45 12
34 63 84 85 86 87 88 71 46 13
33 62 83 96 97 98 89 72 47 14
32 61 82 95 00 99 90 73 48 15
31 60 81 94 93 92 91 74 49 16
30 59 80 79 78 77 76 75 50 17
29 58 57 56 55 54 53 52 51 18
28 27 26 25 24 23 22 21 20 19
Private Function Min(ByVal n1 As Double, ByVal n2 As Double) As Double Min = IIf(n1 < n2, n1, n2) End Function
Private Sub Program1()
'根据行、列计算数字, 适合 Print 语句直接输出
Dim m As Integer, n As Integer, s As Integer, Level As Integer Dim D1 As Integer, D2 As Integer, D3 As Integer, D4 As Integer Dim i As Integer, j As Integer
m = Val(InputBox(\输入行数:\输入列数:\ For i = 1 To m For j = 1 To n
Level = Min(i, Min(m - i + 1, Min(j, n - j + 1))) D1 = 1 + 2 * (2 + s - 2 * Level) * (Level - 1) D2 = D1 + n - 2 * Level + 1 D3 = D2 + m - 2 * Level + 1 D4 = D3 + n - 2 * Level + 1 If i = Level Then
Print Format$(D1 + j - Level, \ ElseIf j = Level Then
Print Format$(D4 + m - Level + 1 - i, \
ElseIf i = m - Level + 1 Then
Print Format$(D3 + n - Level + 1 - j, \ Else
Print Format$(D2 + i - Level, \ End If Next j Print Next i End Sub
Private Sub Program2()
'根据数字计算行、列, 适合填充数组
Dim m As Integer, n As Integer, s As Integer, Level As Integer Dim D1 As Integer, D2 As Integer, D3 As Integer, D4 As Integer
Dim i As Integer, j As Integer, k As Integer, Num(1 To 100, 1 To 100) As Integer
m = Val(InputBox(\输入行数:\输入列数:\ For k = 1 To m * n
Level = Int((s - Sqr(4 - 4 * k + s * s)) / 4) + 1 D1 = 1 + 2 * (2 + s - 2 * Level) * (Level - 1) D2 = D1 + n - 2 * Level + 1 D3 = D2 + m - 2 * Level + 1 D4 = D3 + n - 2 * Level + 1 If k - D1 <= D2 - D1 Then i = Level: j = Level + k - D1 ElseIf k - D1 <= D3 - D1 Then i = Level + k - D2: j = n - Level + 1 ElseIf k - D1 <= D4 - D1 Then
i = m - Level + 1: j = n - Level + 1 - k + D3 Else
i = m - Level + 1 - k + D4: j = Level End If
Num(i, j) = k Next k
For i = 1 To m
For j = 1 To n: Print Format$(Num(i, j), \ Print Next i End Sub
Option Explicit
Private Sub Form_Click()
Dim X&, Y&, I&, lInt&, Xs&, Ys, C& Cls
Me.AutoRedraw = True '持久性位图输出
X = Val(InputBox(\请输入横排个数!\请输入数字\得到横向个数 Y = Val(InputBox(\请输入纵排个数!\请输入数字\得到纵向个数
lInt = X * Y '得到总个数
X = X - 1 '因为从1开始的所以要减1个 Y = Y - 1
For I = 1 To lInt '循环个数
If Xs <= X - C And Ys = C Then '横向打印 Xs = Xs + 1
ElseIf Ys < Y - C And Xs >= X - C Then '纵向打印 Ys = Ys + 1
ElseIf Xs > C + 1 Then '反向横向打印 Xs = Xs - 1
ElseIf Ys > C + 1 Then '反向纵向打印 Ys = Ys - 1 Else
C = C + 1 '每循环完一圈就加一个,成为里面一个圈开始 Xs = Xs + 1 '每循环完一圈第一个开始的坐标加一个 End If
CurrentX = Xs * 400 '设置X、Y坐标 CurrentY = Ys * 400
Print I '打印数字
' Print Format(I, \也可以格式化再打印 Next I End Sub
Option Explicit
Private Sub Form_Load()
AutoRedraw = True: ForeColor = vbWhite: Width = 6975: Height = 4185: BorderStyle = 3: Caption = \
Dim i As Long, j As Long, way As Long, mC As Long, mI As Long, k As Long, p As Long, q As
Long
i = 9: j = 10: mC = 1: k = 171 Do
mI = mI + 1: k = k - 1: DoEvents p = i * 400 - 360: q = j * 200 - 160
Line (p, q)-Step(360, 160), vbBlack, BF
CurrentX = p + 40: CurrentY = q: Print CStr(k) If k = 0 Then Exit Do Select Case way
Case 0: j = j - 1 Case 1: i = i - 1 Case 2: j = j + 1 Case 3: i = i + 1 End Select
If mI = mC Then mI = 0: mC = mC + 1: way = IIf(way = 3, 0, way + 1) Loop End Sub
Option Explicit
Private Sub Form_Click()
Const PI As Single = 3.14159265 Dim R() As Long, M&, N& Dim x&, y&, i&, a# '初始化
M = Val(InputBox(\请输入横排个数!\请输入数字\得到横向个数 N = Val(InputBox(\请输入纵排个数!\请输入数字\得到纵向个数
ReDim R(M + 1, N + 1) As Long For x = 0 To M + 1 R(x, 0) = -1 R(x, N + 1) = -1 Next
For y = 0 To N + 1 R(0, y) = -1 R(M + 1, y) = -1 Next
'小虫初始状态
x = 1: y = 1: a = 0: R(x, y) = 1 '小虫爬行
For i = 2 To M * N
If R(x + Round(Sin(a)), y + Round(Cos(a))) = 0 Then x = x + Round(Sin(a)) y = y + Round(Cos(a)) R(x, y) = i
Else
a = a + PI / 2 i = i - 1 End If Next
'输出结果 For x = 1 To M For y = 1 To N
Print Format(R(x, y), \ Next Print Next End Sub
Private Sub Program1()
'根据行、列计算数字, 适合 Print 语句直接输出
Dim m As Integer, n As Integer, s As Integer, Level As Integer Dim D1 As Integer, D2 As Integer, D3 As Integer, D4 As Integer Dim i As Integer, j As Integer
m = Val(InputBox(\输入行数:\输入列数:\ For i = 1 To m For j = 1 To n
Level = Min(i, Min(m - i + 1, Min(j, n - j + 1))) D1 = 1 + 2 * (2 + s - 2 * Level) * (Level - 1) D2 = D1 + n - 2 * Level + 1 D3 = D2 + m - 2 * Level + 1 D4 = D3 + n - 2 * Level + 1 If i = Level Then
Print Format$(D1 + j - Level, \ ElseIf j = Level Then
Print Format$(D4 + m - Level + 1 - i, \ ElseIf i = m - Level + 1 Then
Print Format$(D3 + n - Level + 1 - j, \ Else
Print Format$(D2 + i - Level, \ End If Next j Print Next i End Sub
正在阅读:
螺旋数列多种版本06-21
把工作做到极致读后感03-19
自动控制原理(非自动化类)答案 - 第二版(孟庆明)10-02
2015 - TDD-LTE - 考题11-30
施工电梯监理旁站方案12-16
概率初步测试题(1)11-26
自动控制原理112-15
机械加工原理(终稿)07-21
个人技术工作总结优秀集锦(含五篇)08-23
遗传学课后习题答案09-21
- 多层物业服务方案
- (审判实务)习惯法与少数民族地区民间纠纷解决问题(孙 潋)
- 人教版新课标六年级下册语文全册教案
- 词语打卡
- photoshop实习报告
- 钢结构设计原理综合测试2
- 2014年期末练习题
- 高中数学中的逆向思维解题方法探讨
- 名师原创 全国通用2014-2015学年高二寒假作业 政治(一)Word版
- 北航《建筑结构检测鉴定与加固》在线作业三
- XX县卫生监督所工程建设项目可行性研究报告
- 小学四年级观察作文经典评语
- 浅谈110KV变电站电气一次设计-程泉焱(1)
- 安全员考试题库
- 国家电网公司变电运维管理规定(试行)
- 义务教育课程标准稿征求意见提纲
- 教学秘书面试技巧
- 钢结构工程施工组织设计
- 水利工程概论论文
- 09届九年级数学第四次模拟试卷
- 数列
- 螺旋
- 多种
- 版本
- 330KV进站手续
- 2010年福建省会计从业资格考试模拟试题4
- 外研版选修6 Module 4 Music Section 达标微测
- 唑来膦酸与帕米膦酸二钠治疗恶性肿瘤骨转移疼痛
- 《证券投资学》作业3
- 实验室管理手册
- 学科带头人申报表1
- 用跨文化理论解析电影
- 小学六年级英语毕业复习资料一般过去时的用法
- 机械设计课程设计--带式运输机传动装置
- 第一次河流动力学习题
- 河北省现代物流业十二五发展规划
- 2017年中国科学技术大学070204等离子体物理考研专业目录及考试科
- 期中综合检测1 - 图文
- 广西壮族自治区高等教育自学考试毕业生登记表
- 2016中国矿业大学 学术翻译实践期末试卷答案
- 关于编制瓦楞纸盒项目可行性研究报告编制说明
- 电动车无刷控制器电机线和霍尔线—接法
- 什么是CI,VI,UI
- 2018年人教版三年级数学上册全册教案(含教学反思)