设x=2.5,a=7,y=4.7,求x+a%3*(int)(x+y)%2/4 要说明先算哪步.最好再说说运算符的优先级.

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/16 10:52:05
设x=2.5,a=7,y=4.7,求x+a%3*(int)(x+y)%2/4 要说明先算哪步.最好再说说运算符的优先级.
xRMO@+@ivwxśBШ) H4"D-$Ѩ?Ovզifۙ}3}z>3{+2J YC i})$16Br+M;mVɞ5IZĚ p^t֮c7.W]_ZSZ"o ͯ4R-7'3Q\EtlCl.H@'DŽrsqٻvfO̾{[rFUY@& yvs:#KQ/*){[UB>;(s/-Zwdg 5'Z62^2Dx*-"Ŵ?Y ad rt ֮ʣ3K{r!Ø\N'Zo,hm#!c^!c1 3 R qAK[I?

设x=2.5,a=7,y=4.7,求x+a%3*(int)(x+y)%2/4 要说明先算哪步.最好再说说运算符的优先级.
设x=2.5,a=7,y=4.7,求x+a%3*(int)(x+y)%2/4 要说明先算哪步.最好再说说运算符的优先级.

设x=2.5,a=7,y=4.7,求x+a%3*(int)(x+y)%2/4 要说明先算哪步.最好再说说运算符的优先级.
x+a%3*(int)(x+y)%2/4 //先算(int)(x+y),x+y取整得7
=x+a%3*7%2/4 //算a%3=1
=x+1*7%2/4 //算1*7=7
=x+7%2/4 //算7%2=1
=x+1/4 //算1/4=0
=x+0
=2.5

先算 (int)(x+y) = 7;再算3*(int)(x+y)和2/4 ,分别等于21,0(3*7,2除4取整为0);再算7%21%0,等于0;最后算x+0,等于2.5。

先把未知数代入
2.5+7%*3*int(2.5+7)%*2/4
=2.5+7%*3*9%*2/4
=2.5+7%*3*9%/2
=2.5+63*3/2/10000
=2.5+189/2/10000
=2.5+0.00945
=2.50945

算术运算符是按左结合性运算的,即从左到右,强制类型转换优先级高于求余运算。
1. a%3=1
2. (int)(x+y)=7
3. 1*7=7
4. 7%2=1
5. 1/4=0
6. X+0=2.5