资源描述
程序设计题1、题目:(事件)单击窗体(响应)用输入框输入一自然数,判断是正数、负数或零,并根据输入的 数用消息框显示正数、负数”或零。2、题目:(事件)单击窗体。(响应)求200300之间既能被3整除又能被7 整除的数。并求出所有数之 和存入变量 SUM 中3、题目:单击窗体。(响应)已知S=1+1/4+1/9+1/16+1/25+1/100,结果输出在窗体上。4、 题目(事件)单击窗体。(响应)在窗体上打印数列2/1,3/2,5/3,8/5,13/8的前10项,并求其和,将 和保存在变量 s 中。5、题目:(事件)双击窗体。(响应)把一元钞票换成一分、二分和五分的硬币每种至少有一枚),求出 其所有的换法,把结果输出在窗体上。将所有的换法的数目存入变量N中6、题目:单击窗体。)求1!+2!+3!+4!+5!并将结果输出到窗体上。结果存入变量S中7、题目:(事件)单击窗体。(响应)生成一个一维数组(10个数组元素依此为:15、 23、 72、 43、 96、 23、 3、 65、 88、 17写程序求出这个数组中的最大值、最小值和平均值,并输出在窗体上。将最大值,最小值,平均值分 别存入变量Max,Min,Aver中8、题目:(事件)单击窗体。(响应)在窗体上输出100200之间的所有合数。求出所有数之和存入SUM 中所谓合数是指自然数中能被1和本数整除以外,还能被其他数整除的数。9、题目:(事件)单击窗体。(响应)求1020之间所有素数的乘积 中。10、题目:(事件)单击窗体。(响应)求1 -1/2 + 1/3 -1/41题n = InputBox(输入一个自然数)If n 0 ThenresultElseIf n max Then =a(i)s =Nextaver = Int(s / 10) Print (CStr(max) Print (CStr(min) Print (CStr(aver) 8题Dim i, j, s As IntegeFor i = 100 To 200For j = 2 To If (i Mod j)Print (CStr(i) sum = sum + iExit Ford IftNNexFor j =题Dim lFori%. n Then t = m: m = n: n = tProgram* End *End FunctionPrivate Sub Form_Load()ShowPrint fun(4, 2)NJIT_VBEnd SubPrivate Sub NJIT_VB()Dim i As IntegerDim a(10) As StringDim fIn As IntegerDim fOut As IntegerfIn = FreeFileOpen App.Path & in.dat For Input As #fInfOut = FreeFile如:应Open App.Path & out.dat For Output As #fOutFor i = 1 To 10 Step 2Line Input #fIn, a(i) Line Input #fIn, a(i + 1)Print #fOut, Trim(Str(fun(Val(a(i), Val(a(i + 1)NextClose #fInClose #fOutEnd Sub18、题目:编写函数fun,函数的功能是:判断一个数是否为素数。并显7 该数为素数时,显示素数;该数为非素数时,显示非素数要求使用For语句来实现,用布尔型变 量flag作为该数是否为素数的标志,注意:不得使用GPrivate Function fun(m As Long) As StringDim flag As Boolean*Program* End *End FunctionPrivate Sub Form_Load()ShowPrint fun(225)End SubNJIT_VBPrivate Sub NJIT_VB()Dim i As Integer Dim 0) As StringfIn As Integer Dim fOut As Integer fIn = FreeFileOpen App.Path & in.dat For Input As #fIn fOut = FreeFileOpen App.Path & out.dat For Output As #fOut For i = 1 To 10 Step 1Line Input #fIn, a(i)Print #fOut, fun(Val(a(i)NextClose #fInClose #fOutEnd SubNextClose #fInClose #fOutEnd Sub19、题目:编写函数fun,函数的功能是:求1T00以内能被m整除或能被n整除的数的总和并显示。如:m为15,n为11时,显示EIO,存储总和的变量必须为Sum,要求使用For语句来实现。Private Function fun(m As Integer, n As Integer) As LongDim Sum As LongProgram* End *End FunctionPrivate Sub Form_Load()ShowPrint fun(15, 11)NJIT_VBEnd SubPrivate Sub NJIT_VB()Dim i As IntegerDim a(10) As StringDim fIn As IntegerDim fOut As IntegerfIn = FreeFileOpen App.Path & in.dat For Input As #flnfOut = FreeFileOpen App.Path & out.dat For Output As #fOutFor i = 1 To 10 Step 2Line Input #fIn, a(i)Line Input #fIn, a(i + 1)Print #fOut, Trim(Str(fun(Val(a(i), Val(a(i +NextClose #fInClose #fOutEnd Sub20、题目:编写函数fun,函数的功能是:计算并输出给定整数n的所有因子之和(不包括1与自身)。 规定n的值不大于1000?例如:n的值为855时,应输出704。21、题目:编写函数fun其功能是:判断一个整数w的各位数字平方之和能否被5整除,可以被5 整除则返回1 ,否则返回022、题目:编写函数fun其功能是:根据整型形参y=1/5+1/6+1/7+1/8+1/9+1/10.+1/(m+5)求:函数中用到的中间变量必须声明为Single类型。11题Dim idim sFor iai j IforAs Integer integer 500 To 1 Step -1=i 一 1 To 1 Step -1 i Mod j = 0 Thens = s - jEnd IfNext jIf s = 0 Then)m,计算如下公式的值:Exit ForEnd IfNext iPrint i sum=i 12题Dim i, j, imin, temp As IntegerFor i = 1 To n - 1imin = iFor j = i + 1 To nIf a(imin) a(j) Then imin = jNext j temp = a(i) a(i) = a(imin) a(imin) = tempNext i13题Dim i As IntegerFor i = 2 To 1000If i Mod 3 = 2 And i Mod 5 = 3 And i Mod 7 = 2 Then Print iExit ForEnd IfNext isum = i14 题If UCase(n) = A And UCase(n) = 0 And n =90 then Fun=优秀Elself mark =80 then Fun=良好Elseif mark=70thenthenDo While x yx * 1.008n + 1Loopnt * iNext iFun=中等Elseif mark=60Fun=及格ElseFun二不及格x 二fun =n =m 一 1n = 0For i = m To n16题x = 1017题Product =grueFor2 ToProdu = Prn = Pro18题fIf m Mod i = 0 Then flag = FalseNext iIf flag Thenfun = 素数Else19 题Sum = 0For i = 1 To 100If i Mod m = 0 Or i Mod n = 0 ThenSum = Sum + iEnd IfNext i20题Dim s, i As IntegerFor i = 2 To n - 1If n Mod i = 0 Then s = s + iEnd IfNext21题Dim k As Integer, s As Integer Dos = s + (w Mod 10) * (w Mod 10) w = Int(w / 10)Loop While w 0If s Mod 5 = 0 Thenk = 1Elsek = 0End Iffun = k22题Dim y As DoubleDim i As IntegerFor i = 0 To m y = y + 1 / (i + 5)NextFun = y
展开阅读全文