c语言中如果a=7,b=5,c=18,则逻辑表达式!(a+b)+c-17&&b<a-c/6的值为
时间: 2024-03-04 21:53:31 浏览: 59
该逻辑表达式的值为 0。
首先,根据 C 语言运算符的优先级,逻辑非运算符 ! 的优先级最高,因此先计算 !(a+b) 的值。由于 a+b 的值为 12,而逻辑非运算符将非零值转换为 0,将零值转换为 1,因此 !(a+b) 的值为 0。
接下来,根据运算符的优先级和结合性,计算表达式中的其它运算。由于算术运算符 +、-、/、* 的优先级高于逻辑运算符 &&,因此先计算 c-17 和 a-c/6。注意,C 语言中整数除法会向下取整,因此 c/6 的值为 3。因此 a-c/6 的值为 4。
接着,根据逻辑与运算符的规则,只有两个操作数都为真(非零)时,结果才为真。因为 !(a+b) 的值为 0,因此整个逻辑表达式的值为 0。
相关问题
如果a=7,b=5,c=18,则逻辑表达式!(a+b)+c-17&&b<a-c/6的值为多少?用c语言回答
根据运算符优先级,先计算括号内的表达式,再计算逻辑非运算符 !,最后计算逻辑与运算符 &&,该表达式的值可以用以下的C语言代码实现:
```c
int a = 7, b = 5, c = 18;
int result = !(a + b) + c - 17 && b < a - c / 6;
printf("%d\n", result); // 输出1
```
因为 !(a+b) 的值为0,所以 !(a+b)+c-17 的值为1,而 b<a-c/6 的值也为1,因此逻辑与运算符的结果为1。
如果a=7,b=3,c=18,则逻辑表达式!(a+b)+c-17&&b<a-c/6的值为多少?用c语言回答
同样的方式,将a赋值为7,b赋值为3,c赋值为18,然后计算逻辑表达式 !(a+b)+c-17&&b<a-c/6 的值,可以用以下的C语言代码实现:
```c
int a = 7, b = 3, c = 18;
int result = !(a + b) + c - 17 && b < a - c / 6;
printf("%d\n", result); // 输出0
```
因为 !(a+b) 的值为0,所以 !(a+b)+c-17 的值为1;而 b<a-c/6 的值为0,因为 a-c/6 的值为6,而6不小于3,所以逻辑比较的结果为0。因此逻辑与运算符的结果为0。
阅读全文
相关推荐
















