欢迎来到天天文库
浏览记录
ID:22021981
大小:381.50 KB
页数:36页
时间:2018-10-21
《c语言英文版课件》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、IntroductiontoComputer(CProgramming)SoftwareCollege,NortheasternUniversity2007,9Chapter3OperatorsandExpressions3.1introductionCoperatorscanbeclassifiedintoanumberofcategories.Theyinclude:Arithmeticoperators.Relationaloperators.Logicaloperators.Assign
2、mentoperators.Incrementanddecrementoperators.Conditionaloperators.Bitwiseoperators.Specialoperators.3.2ArithmeticoperatorsOperatorMeaning+Additionorunaryplus-Subtractionorunaryminus*Multiplication/Division%ModulodivisionExamples:a-b,a+b,a*b,a/b,a%bExa
3、mple3.1TheProgramshowstheuseofintegerarithmetictoconvertagivennumberofdaysintomonthsanddays.main(){intmonths,days;printf(“Enterdays”);scanf(“%d”,&days);months=days/30;days=days%30;printf(“Months=%ddays=%d”,months,days);}OutputEnterdays265Months=8Day
4、s=25Enterdays364Months=12Days=4Enterdays45Months=1Days=153.3RelationalOperatorsCsupportssixrelationaloperatorsinall:OperatorsMeaningisgreaterthan>=isgreaterthanorequalto==isequalto!=isnotequaltoExample4.5<=104.5<-10-35
5、>=010<7+5a+b=c+d?RelationalOperatorComplementsAmongthesixrelationaloperators,eachoneisacomplementofanotheroperator.>iscomplementof<====iscomplementof!=Wecansimplifyanexpressioninvolvingthenotandthelessthanoperatorsusingthecomplemen
6、tsasshownbelow:ActualoneSimplifiedone!(x=y!(x>y)x<=y!(x!=y)x==y!(x<=y)x>y!(x>=y)x7、8、meaninglogicalOR!meaninglogicalNOTExample:TruthTableOp_1Op_2Valueof9、theExpressionop_1&&op_2op_110、11、op_2Non_zeroNon_zero11Non_zero0110Non_zero110011Examples:1.if(age>55&&salary<1000)2.if(number<012、13、number>1000)3.5AssignmentOperatorsChasasetof‘shorthand’operatorsoftheform:vop=exp;wherevisavariable,expisanexpressionopisaCbi14、naryarithmeticoperatorop=isknownastheshorthandassignmentoperatorvop=exp;isequivalenttov=vop(exp);Examples:x+=y+1;isequivalenttox=x+(y+1);x+=3;isequivalenttox=x+3;ShorthandAssignmentOperatorsStatementwithsimpleStatementwithassignmentoperatorsho
7、
8、meaninglogicalOR!meaninglogicalNOTExample:TruthTableOp_1Op_2Valueof
9、theExpressionop_1&&op_2op_1
10、
11、op_2Non_zeroNon_zero11Non_zero0110Non_zero110011Examples:1.if(age>55&&salary<1000)2.if(number<0
12、
13、number>1000)3.5AssignmentOperatorsChasasetof‘shorthand’operatorsoftheform:vop=exp;wherevisavariable,expisanexpressionopisaCbi
14、naryarithmeticoperatorop=isknownastheshorthandassignmentoperatorvop=exp;isequivalenttov=vop(exp);Examples:x+=y+1;isequivalenttox=x+(y+1);x+=3;isequivalenttox=x+3;ShorthandAssignmentOperatorsStatementwithsimpleStatementwithassignmentoperatorsho
此文档下载收益归作者所有