(3.5)--3.5Relationaloperatorsandrelatio.pdf

上传人:刘静 文档编号:57974845 上传时间:2022-11-06 格式:PDF 页数:6 大小:420.22KB
返回 下载 相关 举报
(3.5)--3.5Relationaloperatorsandrelatio.pdf_第1页
第1页 / 共6页
(3.5)--3.5Relationaloperatorsandrelatio.pdf_第2页
第2页 / 共6页
点击查看更多>>
资源描述

《(3.5)--3.5Relationaloperatorsandrelatio.pdf》由会员分享,可在线阅读,更多相关《(3.5)--3.5Relationaloperatorsandrelatio.pdf(6页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、Relational Operators&Relational ExpressionsRelational Operators&Relational Expressions3.5Relational operators are used to compare the magnitude relationship oftwo operands.The result of the relational operator is a Bool value.Ifthe relationship is established,the result is logically true,otherwise i

2、tis logically false.Relational Operators&Relational ExpressionsRelational Operators&Relational Expressions3.5Assume the defined variables:int m=7,n=5;OperatorMeaningFunctionExampleResultLess thanIf the left operand is less than the right operand,the result is true,otherwise the result is false.mnfal

3、se=Less than or equal toIf the left operand is less than or equal to the right operand the result is true,otherwise the result is false.mMore thanIf the left operand is more than the right operand,the result is true,otherwise the result is false.mntrue=More than or equal toIf the left operand is mor

4、e than or equal to the right operand the result is true,otherwise the result is false.m=ntrue=Equal toIf the left operand is equal to the right operand,the result is true,otherwise the result is false.m=nfalse!=Not equal toIf the left operand is not equal to the right operand the result is true,othe

5、rwise the result is false.m!=ntrueRelational Operators&Relational Expressions3.5E.g.1If a positive number n is needed to participate in the calculation,write arelationship expression that determines whether n is a positive number.Solution:n0Explanation:If the relational expression n 0 is true,it mea

6、ns that n is apositive number greater than 0 and can participate in the operation;otherwise,n cannot participate in the operation.E.g.2Write an expression that determines whether x is evenly divisible by 5.Solution:x%5=0Explanation:The arithmetic operator%is used here.If the remainder of xdivided by

7、 5 is 0,it means x isevenlydivisible by 5.Relational Operators&Relational Expressions3.5E.g.3Assuming that a is not equal to 0,write a relational expression thatjudges whether the unary quadratic equation ax2+bx+c=0 has real roots.Solution:b*b-4*a*c=0Explanation:If the result of the relational expre

8、ssion b*b-4*a*c=0 istrue,then the quadratic equation ax2+bx+c=0 has real roots;Otherwise the unary quadratic equation ax2+bx+c=0 has no real root.Question:Multiple types of operators are mixed together,which oneshould be counted first?Relational Operators&Relational Expressions3.5The relational oper

9、ators =should not havespaces between the two symbols,that is,“=When multiple operators are together,the type of expression and thetype of expression value are determined by the last operatorevaluated.For example,int x=5,y=3;then x+1y-2 is a relational expression whose value is true(Booltype).Note the difference between the relational operator=and theassignment operator=.Tips:

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 大学资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com