《VB循环应用的程序设计.docx》由会员分享,可在线阅读,更多相关《VB循环应用的程序设计.docx(6页珍藏版)》请在第一文库网上搜索。
1、实验名称:循环应用的程序设计实验目的1)熟悉循环嵌套在程序设计中的运用,内外层循环的协调。2)掌握For语句和D。While语句的使用环境,学会控制精度的级数计算。3)熟悉Exit语句和Continue语句的使用。实验环境Visual Studio 2008实验内容1)求3300之间所有素数要求格式单击“输出素数”命令按钮,在文本框中输出3-300之间所有素数,每行输出9个素数。对齐,程序运行界面如图1所示。尸.求33OO之间所有素数E输出素数3571113171923293137414347535961677173798389971011031071091131271311371391491
2、51157End Class2)计算具有精度的级数a r 5 r图2计算具有精度的级数控件的主要属性:Button 1:TextText.boxl: MultiLine (True), Readonly (True, ScrollBar (Vertical).Label.Text1-2:Text程序代码:Imports System. MathPublic Class FormlPrivate Sub Buttonl Click (ByVai sender As Object, ByVai e As System. EventArgs)Handles Buttonl.ClickDim i, f
3、lag As Integer, s, item, x, t As Doublex = Vai(TextBoxl. Text)s = 1 + (3 * x) / 2t = 3 / 2item = t * x 二 2 flag = -1 7 rDo ort = (2 * i + 1) / (i * (i + 1)item = t * (x - i) * flagi = i + 1 图2计算具有精度的级数控件的主要属性:Button 1:TextText.boxl: MultiLine (True), Readonly (True, ScrollBar (Vertical).Label.Text1-
4、2:Text程序代码:Imports System. MathPublic Class FormlPrivate Sub Buttonl Click (ByVai sender As Object, ByVai e As System. EventArgs)Handles Buttonl.ClickDim i, flag As Integer, s, item, x, t As Doublex = Vai(TextBoxl. Text)s = 1 + (3 * x) / 2t = 3 / 2item = t * x计算级数S = l+一 +上U + .,直到精度达到10-5。在文本框中输入X,
5、单击“计12 23 3x4 45算”命令按钮,在标签中输出计算结果。程序运行界面如图2所示。旧计算具有精度的级数2JLJ:.3946反算|结果:1.4897052)计算具有精度的级数a r 5 r 二 2 flag = -1 7 rDo ort = (2 * i + 1) / (i * (i + 1)item = t * (x - i) * flagi = i + 1 图2计算具有精度的级数控件的主要属性:Button 1:TextText.boxl: MultiLine (True), Readonly (True, ScrollBar (Vertical).Label.Text1-2:Te
6、xt程序代码:Imports System. MathPublic Class FormlPrivate Sub Buttonl Click (ByVai sender As Object, ByVai e As System. EventArgs)Handles Buttonl.ClickDim i, flag As Integer, s, item, x, t As Doublex = Vai(TextBoxl. Text)s = 1 + (3 * x) / 2t = 3 / 2item = t * x计算级数S = l+一 +上U + .,直到精度达到10-5。在文本框中输入X,单击“计
7、12 23 3x4 45算”命令按钮,在标签中输出计算结果。程序运行界面如图2所示。旧计算具有精度的级数2JLJ:.3946反算|结果:1.4897052)计算具有精度的级数a r 5 r 二 2 flag = -1 7 rDo ort = (2 * i + 1) / (i * (i + 1)item = t * (x - i) * flagi = i + 1 图2计算具有精度的级数控件的主要属性:Button 1:TextText.boxl: MultiLine (True), Readonly (True, ScrollBar (Vertical).Label.Text1-2:Text程序
8、代码:Imports System. MathPublic Class FormlPrivate Sub Buttonl Click (ByVai sender As Object, ByVai e As System. EventArgs)Handles Buttonl.ClickDim i, flag As Integer, s, item, x, t As Doublex = Vai(TextBoxl. Text)s = 1 + (3 * x) / 2t = 3 / 2item = t * x计算级数S = l+一 +上U + .,直到精度达到10-5。在文本框中输入X,单击“计12 2
9、3 3x4 45算”命令按钮,在标签中输出计算结果。程序运行界面如图2所示。旧计算具有精度的级数2JLJ:.3946反算|结果:1.4897052)计算具有精度的级数a r 5 r 二 2 flag = -1 7 rDo ort = (2 * i + 1) / (i * (i + 1)item = t * (x - i) * flagi = i + 1 = s + itemflag = -flagLoop Until (Abs(item) 0.00001)Label2. Text = 结果: & Format (s, 0.000000)End Sub计算级数S = l+一 +上U + .,直到
10、精度达到10-5。在文本框中输入X,单击“计12 23 3x4 45算”命令按钮,在标签中输出计算结果。程序运行界面如图2所示。旧计算具有精度的级数2JLJ:.3946反算|结果:1.489705End Class3)输出三角形图案在窗体上建立文本框作为输出三角形图案的画布。分别单击“左上角”、“右上角”、“左下角”和“右s = s + itemflag = -flagLoop Until (Abs(item) 0.00001)Label2. Text = 结果: & Format (s, 0.000000)End Subs = s + itemflag = -flagLoop Until (Abs(item) 0.00001)Label2. Text = 结果: & Format (s, 0.000000)End Subs = s + itemflag = -flagLoop Until (Abs(item) 0.00001)Label2. Text = 结果: & Format (s, 0.000000)End Sub