【VB开源代码栏目提醒】:网学会员在VB开源代码频道为大家收集整理了“算法VB程序(必修3学习) - 技术总结“提供大家参考,希望对大家有所帮助!
1 算法VB程序 1.2.1输入语句、输出语句和赋值语句 1三元一次函数求值 x InputBoxprompt tittle 相当于 INPUT “x” x y x 3 3 x 2 - 24 x 30 print y 2计算平均值 a InputBoxprompt tittle b InputBoxprompt tittle c InputBoxprompt tittle Print the average Vala Valb Valc / 3 3给一个变量重复赋值 A 10 A A 15 Print A 4交换数字 a InputBoxprompt tittle 2 b InputBoxprompt tittle Print a b x b b a a x Print a b 练习题 1温度 c InputBoxprompt tittle f c - 32 5 / 9 Print f 2加减乘除 a InputBoxprompt tittle b InputBoxprompt tittle Print sum Vala Valb Print diff Vala - Valb Print pro Vala Valb Print qvo Vala / b 3海伦秦九韶公式 3 a InputBoxprompt tittle b InputBoxprompt tittle c InputBoxprompt tittle p 1 / 2 Vala Valb Valc s p p - Vala p - Valb p - Valc 1 / 2 Print p s 4应用题 a InputBoxprompt tittle b InputBoxprompt tittle c InputBoxprompt tittle p 10.4 Vala 15.6 Valb 25.2 Valc Print p 1.2.2条件语局 1求绝对值 方法一 x InputBoxprompt tittle If x 0 Then Print x 4 Else Print -x End If 方法二 x InputBoxprompt tittle If x 0 Then x -x End If Print x 2二元一次方程 a InputBoxprompt tittle b InputBoxprompt tittle c InputBoxprompt tittle d b 2 - 4 a c If d 0 Then p -b / 2 a q Sqrd / 2 a If d 0 Then Print x1x2 p Else Print x1x2 p q p - q End If 5 Else Print no real root 3大小排序 a InputBoxprompt tittle b InputBoxprompt tittle c InputBoxprompt tittle d b 2 - 4 a c If b a Then t a a b b t End If If c a Then t a a c c t End If If c b Then t b b c c t End If 6 Print a b c end if 练习题 1图1.1-10三角形的三边的关系 a InputBoxprompt tittle b InputBoxprompt tittle c InputBoxprompt tittle If Vala Valb Valc And Valc Valb Vala And Vala Valc Valb Then Print 存在这样的三角形 Else Print 不存在这样的三角形 End If 2阅读程序 Print please input an integer: x x InputBoxprompt tittle If x 9 And x 100 Then a x 10 b x Mod 10 7 x 10 b a Print x a b End If 3编写一个程序判断任意输入的整数的奇偶性 x InputBoxprompt tittle r Valx Mod 2 If r 0 Then Print x是偶数 Else Print x是奇数 End If 4闰年 方法一 Print 请输入年份 y InputBoxprompt tittle r Valy Mod 400 l Valy Mod 100 k Valy Mod 4 If r 0 Or l 0 And k 0 Then 8 Print y是闰年 Else Print y不是闰年 End If 方法二 Print 请输入年份 y InputBoxprompt tittle If y Mod 4 0 Then Print y是闰年 Else If y Mod 100 0 Then Print y不是闰年 Else If y Mod 400 0 Then Print y是闰年 Else Print y不是闰年 End If End If End If 9 1.2.3循环语句 1.从1加到100 i 1 s 0 Do s s i i i 1 Loop Until i 100 Print s i 1 s 0 While i 11 3.二分法 a InputBoxprompt tittle b InputBoxprompt tittle d InputBoxprompt tittle Do m Vala Valb / 2 g a 2 - 2 f m 2 - 2 If g f 0 Then b m Else a m End If Loop Until Absa - b Vald Or f 0 Print m g f 练习题 1.判断大于2的数是否为质数 11 n InputBoxprompt tittle i 2 Do r n Mod i i i 1 Loop Until i n - 1 Or r 0 If r 0 Then Print n不是质数 Else Print n是质数 End If 2.计算n的阶数 n InputBoxprompt tittle i 1 s 1 Do s s i i i 1 Loop Until i Valn Print s 12 习题1.2 A组 1.阅读程序 x InputBoxprompt tittle If x 0 Then y -x 1 Else If x 0 Then y 0 Else y x 1 End If End If Print y End 2编写一个程序输入梯形的上底、下底和高的值计算并输出其面积。