1樓:匿名使用者
- -! 五十分太少,十幾道題,太虧了,不做- -!
2樓:蒼鬱
你把題分開,一道題一個帖子,就會有很多人幫你做了,都是些很簡單的題
3樓:匿名使用者
- -! 五十分太多,十幾道題,太賺了,我做- -!
4樓:匿名使用者
1. 在文字框text1中輸入一串字元,統計其中字母(不區分大小寫),數字和其他字元的個數。
dim i as integer, a as integer, b as integer, str as string
if text1.text <> "" then
str = ucase(text1.text)
for i = 1 to len(str)
select case asc(mid(str, i, 1))
case 65 to 90
a = a + 1
case 48 to 57, 60 to 69
b = b + 1
end select
next i
print "letter:" & a & vbcrlf & "numeral:" & b
end if
2. 輸入一個整數,判斷該數是否是素數。
dim i as integer, n as string
if text1.text <> "" then
n= text1.text
for i = 2 to int(sqr(n))
if n mod i = 0 then
print "不是"
exit sub
end if
next i
print "是"
end if
3. 隨機產生20個200~400之間的隨機整數,按每行4個輸出到picture中,並求出其中的最大值。
dim i as integer, ii as integer, myvalue as integer, maxvalue as integer, str as string
randomize
for i = 0 to 4
for ii = 0 to 3
myvalue = int(((2 * rnd) + 2) * 100)
str = str & myvalue & " "
if maxvalue < myvalue then maxvalue = myvalue
next
picture1.print rtrim(str) & vbcrlf
str = ""
next i
picture1.print "max:" & maxvalue
4. 隨機產生10個數存入陣列中,用選擇排序法對其從小到大的順序排序。
dim a(9) as integer, i as integer, j as integer, str as string
randomize
for i = 0 to 9
a(i) = 1 + rnd * 1000
str = str & " " & (a(i))
next
print "原值:" & str
dim min, temp as integer
for i = 0 to 8
min = a(i)
for j = i + 1 to 9
if min > a(j) then
temp = a(j)
a(j) = min
min = temp
end if
next
a(i) = min
next
str = "排序:"
for i = 0 to 9
str = str & " " & a(i)
next
print str
5.輸入一個整數,判斷該數是否是迴文數。
dim a as string, n as integer, i as integer
if text1.text <> "" then
a = text1.text
n = len(a)
for i = 1 to n
if mid(a, i, 1) <> mid(a, n - i + 1, 1) then exit for
next i
if i = n + 1 then
print "是迴文數"
else
print "不是迴文數"
end if
end if
6. 輸入一個整數,判斷該數是否是水仙花數
dim a as integer, b as integer, c as integer
if len(text1.text) = 3 then
a = (val(text1.text) \ 100) mod 10
b = (val(text1.text) \ 10) mod 10
c = val(text1.text) mod 10
if a ^ 3 + b ^ 3 + c ^ 3 = a * 100 + b * 10 + c then
print "是水仙花數"
else
print "不是水仙花數"
end if
end if
7. 分別輸入年份以及月份,輸出該月所對應的天數(注意閏年問題)。
dim a as date, b as date
a = dateserial(val(text1.text), val(text2.text), 1)
b = dateserial(val(text1.text), val(text2.text) + 1, 1)
print a & "年"; b & "月 共有:" & datediff("d", a, b) & "天"
8.建立一個登入視窗,要求輸入密碼。
dim erronum as integer
private sub cmdok_click()
if txtpassword.text = "abcdefg" then
msgbox "祝賀你,成功登入!", , "登入"
else
erronum = erronum + 1
msgbox "對不起,密碼錯誤,無法登入!", , "登入"
if erronum = 3 then end
end if
end sub
9.求任意正整數 n 的階乘。(n!=1*2*3*……*n)
dim n as integer, m as double
n = inputbox("please input n:")
m = 1
for i = 1 to n
m = m * i
next i
print m
10.編寫程式,輸出輸出n=7「楊輝三角」
n = 7
redim a(1 to n, 1 to n)
clsfor i = 1 to n
a(i, 1) = 1
a(i, i) = 1
next i
for i = 3 to n
for j = 2 to i - 1
a(i, j) = a(i - 1, j) + a(i - 1, j - 1)
next j, i
for i = 1 to n
print tab(30 - 2 * i);
for j = 1 to i
print space(4 - len(trim(str(a(i, j))))); trim(str(a(i, j)));
next j
next i
11.斐波那契數列又因數學家列昂納多•斐波那契以兔子繁殖為例子而引入,故又稱為「兔子數列」。
dim i as integer, j as integer, k as integer, sum as double
j = 1
for i = 0 to 12
sum = j + k
j = k
k = sum
print i & " " & sum
next i
12.分類統計輸入一串字元,統計各字母出現的次數,不區分字母大小寫。
dim i as integer, n as integer, j as integer, str as string, m as string
if text1.text <> "" then
str = ucase(text1.text)
for i = vbkeya to vbkeyz
m = chr(i)
j = 0
n = 1
do while n <= len(str)
n = instr(n, str, m)
if n > 0 then
j = j + 1
else
exit do
end if
n = n + 1
loop
if j > 0 then print m & ":" & j
next i
end if
5樓:
第七題option explicit
private sub command1_click()dim year%,month%,day%year=val(text1.text)
month=val(text2.text)if isnumeric(year) thendoevents
else
msgbox("it's not a right number")exit sub
end if
if isnumeric(month) and (month>1 and month<12) then
doevents
else
msgbox("it's not a right number")exit sub
end if
select case month
case 1,3,5,7,8,10,12
msgbox("number of day:31" )case 4,6,9,11
msgbox("number of day:30" )case 2
if (year mod 4=0 and year mod 100<>0) or (year mod 100=0 and year mod 400=0) then
msgbox ("number of day:29" )else
msgbox("number of day:28" )end if
end select
end sub
VB程式設計題,VB程式設計練習題?
1.新建工程 工程1 2.新建一下combobox控制元件 combo1,並將屬性style改為2 3.新建五個label label1,label2,label3,label4,label5 4.新建兩個text文字框 text1,text2 5.新建一個commandbutton按鈕 comma...
vb程式設計題?這道vb題怎麼寫程式碼?
private sub command1 click max val val text2.text val val val text5.text val val val text8.text val val min val val text2.text val val val text5.text ...
vb程式設計設計題 紅綠燈,VB程式設計設計題 紅綠燈
如圖在窗體上新增 1 四個shape控制元件,作為燈框 紅燈 黃燈 綠燈,分別命名為 lampbox redlamp yellowlamp greenlamp 2 一個命令按鈕,命名為 cmdrun,標題為 啟動 3 三個文字框控制元件,來設定紅燈 黃燈 綠燈亮的時間 秒 分別命名為 txtredt...