gpt4 book ai didi

c - 如何判断一个整数是否属于某个整数范围?

转载 作者:行者123 更新时间:2023-11-30 21:21:58 24 4
gpt4 key购买 nike

我想将一个值与范围的两端进行比较。这就是我的代码的样子:

if ( timeramount >5 && <10 )...do some stuff...

所以我的应用程序需要知道是否 timeramount大于 5 但小于 10。

有人可以帮忙吗?

最佳答案

逻辑运算符,例如&& , ||等等取两个操作数。这些操作数必须是表达式。 < 10不是一个有效的表达式,因为它缺少一个操作数(“小于 10 的是什么?”)。

要用 C 语言表达您在自然语言中描述的“如果 timerarount 大于 5 但小于 10”,您必须更详细:

if (timeramount > 5 && timeramount < 10) {
/* if timeramount is greater than 5 AND timeramount is less than 10 */
;
}

我建议您阅读一本很好的 C 入门书籍,以学习该语言的基础知识。 Kernighan & Ritchie 的《C 编程语言》是一个很好的开始,但您可以引用 this question .

关于c - 如何判断一个整数是否属于某个整数范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15711116/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com