資源描述:
《VB編程程序代碼.doc》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、VB編程程序代碼?1、求100以內(nèi)的素Private?Sub?Form_Click()Dim?i%,?j%For?i?=?2?To?100For?j?=?2?To?i?-?1????If?i?Mod?j?=?0?Then?Exit?For??Next?j????If?j?=?i?Then?Print?iNext?iEnd?Sub2、從鍵盤輸入任意長度的字符串,要求將字符順序倒置例如,將輸入的“ABCDEFG”變換成“GFEDCBA”。Private?Sub?Command1_Click()Dim?a$,?I%,?c$,?d$,?n%a?=?In
2、putBox$("輸入字符串")n?=?Len(a)For?I?=?1?To?Int(n??2)???c?=?Mid(a,?I,?1)???Mid(a,?I,?1)?=?Mid(a,?n?-?I?+?1,?1)???Mid(a,?n?-?I?+?1,?1)?=?c???Next?I???Print?a???End?Sub3、計(jì)算0~200之間所有能被11或5整除的數(shù)之和Private?Sub?Form_Click()Dim?n%,?i%n?=?0??For?i?=?1?To?200????If?i?Mod?11?=?0?Or?i?Mod?5?
3、=?0?Then????n?=?n?+?i????End?If??Next?i?Print?nEnd?Sub4、輸入一年份,判斷它是否為閏年,并顯示有關(guān)信息。(判斷閏年的條件是:年份能被4整除但不能被100整除,或者能被400整除)Private?Sub?Command1_Click()Dim?y%y?=?InputBox("請(qǐng)輸入年數(shù)")If?y?Mod?4?=?0?And?y?Mod?100?<>?0?Or?y?Mod?400?=?0?Then??MsgBox?(y?&?"年是閏年")Else??MsgBox?(y?&?"年是平年")End
4、?IfEnd?Sub5、已知x,y,z?3個(gè)變量中存放了3個(gè)不同的數(shù),比較它們的大小并進(jìn)行調(diào)整,使得x?y?Then?t?=?x:?x?=?y:?y?=?tIf?x?>?z?Then?t?=?x:?x?=?z:?z?=?tIf?y?>?z?Then?t?
5、=?y:?y?=?z:?z?=?tPrint?"排序后";?x;?"??";?y;?"???";?zEnd?Sub6、求s=a+aa+aaa+...aaaaa(n個(gè)a),其中a和n的值隨機(jī)產(chǎn)生,a的范圍是[1,9]的整數(shù),n的范圍是[5,10]。如a=3,n=6,則s=3+33+333+3333+33333+333333。編程確定n和a的值,并計(jì)算s。Private?Sub?Form_Click()???Dim?s!,?t!,?i!,?a%,?n%???a?=?Int(Rnd?*?9?+?1)???n?=?Int(Rnd?*?6?+?5)???
6、t?=?0:?s?=?0???Print?"a=";?a,?"n=";?n???For?i?=?1?To?n???????t?=?t?*?10?+?a???????s?=?s?+?t???????Print?t;???Next?i???Print???Print?"s=";?s?End?Sub7、計(jì)算100~300之間所有能被3和7整除的數(shù)之和。Private?Sub?Form_Click()For?i?=?100?To?300If?i?Mod?21?=?0?Thens?=?s?+?iPrint?i;End?IfNext?iPrintPrint
7、?"s=";?sEnd?Sub8、編程求200--400范圍內(nèi)5的倍數(shù)或7的倍數(shù)之和。(一個(gè)數(shù)如果同時(shí)是7和5的倍數(shù),則只能加一次。)Private?Sub?Command1_Click()???Dim?s1%,s2%,s3%,i%???S1=0S2=0For?i=200?to?400If?i?mod?5?=0?or?i?mod?7=0?then?s1=s1+iEnd?ifNext?i?For?i=200?to?400If?i?mod?5?=0?or?i?mod?7=0?then?s2=s2+iEnd?ifNext?iS3=s1-s2Print
8、?s3End?sub9、找出被3、5、7除,余數(shù)為1的最小的5個(gè)正整數(shù)。Private?Sub?Command1_Click()Dim?CountN%