1 / 10

4.2 基本运算和表达式

4.2 基本运算和表达式. 在 vb 中的基本运算包括 算术运算、关系运算、逻辑运算 三大类。把变量、常量通过运算符、函数和括号等按一定的规则组合起来,构成一个 表达式 。 如数学中的 表达式 在 vb 中是 sqr(b^2-4*a*c) 。. 算术类基本运算. 算术类基本运算优先级:高→低 ^ - * / Mod + - 注意: 1 、有括号的先计算括号内的表达式。 2 、特例:乘幂( ^ )和取负( - )相邻时,取负优先。如: 4^-2 的值为 0.0625

Download Presentation

4.2 基本运算和表达式

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 4.2 基本运算和表达式

  2. 在vb中的基本运算包括算术运算、关系运算、逻辑运算三大类。把变量、常量通过运算符、函数和括号等按一定的规则组合起来,构成一个表达式。 • 如数学中的 表达式 • 在vb中是sqr(b^2-4*a*c)。

  3. 算术类基本运算

  4. 算术类基本运算优先级:高→低 ^ - * / \ Mod + - 注意:1、有括号的先计算括号内的表达式。 2、特例:乘幂(^)和取负(-)相邻时,取负优先。如:4^-2的值为0.0625 例:假定X是一个数值型变量,那么,由函数组成的表达式X mod 2=0的作用是( ) A、用于测试X是否为偶数 B、返回一个整数 C、返回一个奇数 D、用于测试X是否为整数 A

  5. 表达式 将下列数学表达式改写VB表达式 - 2 b 4ac + 3 x 1 + - | x 3 | y Sqr(b*b-4*a*c) (x*x*x+1)/(abs(x+3)-y)

  6. 关系类基本运算 练习 • 1990 MOD 4=0 • “abc”<>“abd” • 150=100 • 10=100/10 注意:1、运算结果只有两种:True和False。2、所有关系运算有相同的优先级 False True False True

  7. 逻辑类基本运算 注意:1、优先级(高→低):Not→And→Or 2、And只有当表达式两边都为True时,其值才为True。 3、Or只要表达式一边的值为True,其值就为True。

  8. 练习: • Not(100<>10) • (25>=10)AND(25<=10) • (25>1000)OR(25>2) False True True

  9. 写表达式练习: X mod 8=0 and x mod 7<>0 2、计算:y= (x*x+1)/(Abs(x)+3) 3、判断a、b、c三条线段能否构成一个三角形。 a+b>c And a+c>b And b+c>a 1、写出表达式,判断X能整除8但不能整除7

  10. 课堂练习 1、设a=2,b=3,c=4,d=5,表达式 a>b And c<=d or 2*a>c的值是 _______. (A) True (B) False (C) -1 (D)1 2、下列运算结果中,值最大的是_______. (A) 3\4 (B)3/4 (C)4 mod 3 (D)3 mod 4

More Related