vbs实现编程算法之一——图形输出
上一篇 /
下一篇 2012-02-13 13:34:35
/ 个人分类:VBScript
最近闲来无聊,看了些编程的算法,用vbs实现了下,算是巩固下vbs
vbs没有像c那样的printf打印函数,只能先用&连接字符串,用vbcrlf来控制换行,然后再用msgbox来显示
**九九乘法表**
dim i,j
for i=1 to 9
for j=1 to i
str=str & j & "*" & i & "=" & i* j & " "
next
str=str & vbCrlf '换行
next
Msgbox str
**杨辉三角**
dim i,j,a(10,10)
'数组赋值
for i =0 to 9
a(i,0)=1
a(i,i)=1
next
for i=2 to 4
for j=1 to i-1
a(i,j)=a(i-1,j-1)+a(i-1,j)
next
next
'打印
for i=0 to 4
for k=0 to 20-i
str=str&space(1)
next
for j=0 to i
str=str & a(i,j) &space(1)
next
str=str & vblf
next
msgbox str
1 B;R p)h
sz2M2}0 1 151Testing软件测试网!QBsrWd/W 1 2 151Testing软件测试网tQ
B_1n? 1 3 3 1 WcSbv.v0 1 4 6 4 1 |
**打印星号**
'打印上半部分
for i=0 to 3
for j=0 to 2-i
str=str &space(1)
next
for k=0 to 2*i
str=str &"*"
next
str=str&vbcrlf
next
'打印下半部分
for i=0 to 2
for j=0 to i
str=str &space(1)
next
for k=0 to 4-2*i
str=str &"*"
next
str=str&vbcrlf
next
msgbox str
*51Testing软件测试网a&n6nY0z
~ ***51Testing软件测试网;Kd |(S,K ***** `yi;Ou T@%p#Nh0 *** ){H `vcr4O-_6^UC*L0 * |
**打印字母(例如输入员字母C,打印如下图形)**
c=Asc("C")-Asc("A")
for i=0 to 2*c
for j =0 to Abs(c-i)
str=str &space(1)
next
for k=0 to c-Abs(c-i)
str=str& Chr(65+k) &space(1)
next
str =str & vbcrlf
next
51Testing软件测试网 T2U(A_G
I{4}
msgbox str
A51Testing软件测试网`zy1sG'`)a A B51Testing软件测试网1D0KH
? @3wn G A B C51Testing软件测试网ic u _vU5m&py A B ]0k@Pq$o.v
s`0 A |
;W8Fc
F
]{/p@@0
收藏
举报
TAG: