1、2022-1-2022022-1-2032022-1-204int a;a =3;2022-1-205#include main( ) float price, discount, total; printf(“Buying price : “); scanf(“%f”, &price); printf(“nDiscount rate : “); scanf(“%f”, &discount); total = price * discount; printf(“The total price is %.2fn”, total);Buying price: _discount?price? to
2、tal?Buying price: 10.00_10.00Buying price: 10.00Discount rate: _Buying price: 10.00Discount rate: 0.25_0.252.50Buying price: 10.00Discount rate: 0.25_Buying price: 10.00Discount rate: 0.25The total price is 2.50_Example:2022-1-206Example:2022-1-2072022-1-2082022-1-2092022-1-2010Example:2022-1-2011Ex
3、ample:2022-1-2012Example:2022-1-2013Example:1252102remainderresult2022-1-2014Example:-73-2-6-1remainderresult2022-1-2015Example:7-3-261remainderresult2022-1-2016Example:2022-1-2017Examples:2022-1-2018Example: 2022-1-2019Example:例 5%2 = -5%2 = 1%10 = 5%1 = 5.5%2例 5/2 = -5/2.0 =例 5%2 = 1 -5%2 = -1 1%1
4、0 = 1 5%1 = 0 5.5%2 ()例 5/2 = 2 -5/2.0 = -2.52022-1-2020课堂练习课堂练习例例1 写出下面程序的输出结果写出下面程序的输出结果void main (void ) int x; x= - 3 + 4 5 - 6 ; x=3 + 4 % 5 - 6 ; x= - 34% (- 6)/5; x=(7+6)%5/2 ; x=a+5; x=24+20; 输出运算结果输出运算结果:11101102402022-1-20212022-1-20222022-1-2023Example:j = +i - 2i5similar to j? 462022-1-2
5、024Example:j = i+ - 2i5similar to j? 362022-1-2025OperationDescriptionExamples of ExpressionValueLess than6 91 (true)=Less than or equal to5 Greater than2 60 (false)=Greater than or equal to9 = 51 (true)=Equal to7 = 50 (false)!=Not equal to6 != 51 (true)2022-1-2026aba & b a | b!a!b000011010110100101
6、1111002022-1-2027/结果结果m=0,n=1例例 a&b /只在只在a为真时,才判别为真时,才判别b的值;的值;例例 a|b /只在只在a为假时,才判别为假时,才判别b的值;的值;例例 a=1;b=2;c=3;d=4;m=1;n=1;(m=ab)&(n=cd)2022-1-2028OperationExamples of expressionDescription+=num += 5;num = num + 5;-=num -= 5;num = num 5;*=num *= 5;num = num * 5;/=num /= 5;num = num / 5;%=num %= 5;n
7、um = num % 5;2022-1-2029能背下优先级表的人凤毛麟角能背下优先级表的人凤毛麟角 脑细胞太宝贵了,不能用来死记硬背脑细胞太宝贵了,不能用来死记硬背用括号来控制运算顺序更直观、方便,用括号来控制运算顺序更直观、方便,并减少出错的概率并减少出错的概率 先算乘除,后算加减,有括号就先算括号先算乘除,后算加减,有括号就先算括号里的里的 括号太多,有时候不清晰括号太多,有时候不清晰 注意用注意用空格空格做好分隔做好分隔 实在不行就拆分表达式实在不行就拆分表达式2022-1-2030doublefloatlongunsignedintchar,short低高2022-1-2031【例例2-42-4】:给出并分析下面三段程序的输出结果:给出并分析下面三段程序的输出结果2022-1-2032Example: int x = 10;float y;y = (float)x;x10y?10.000000