检查数组中的所有值
Checking all values in an array
我有一个这样的数字数组:
int array[5];
我正试图打破一段时间的循环。我基本上想说如果数组中的所有数字都大于 100,然后结束循环。
有没有办法处理它?
您可以检查数组中的每个元素,如果只有元素小于 100,则中断。
在循环外部,根据i
- 循环计数器 - 是否等于大小来打印消息。如果等于所有元素都大于,否则其中一个元素较小:
int array[] = {271, 120, 469, 77, 2000};
//int array[] = {271, 120, 469, 787, 2000}; // uncomment this line and comment out the line above to see the difference.
int i = 0;
for(; i < 5; i++)
if(100 > array[i])
break;
if(i != 5)
std::cout << "Not all the values are greater than 100" << std::endl;
else
std::cout << "All the values are greater than 100" << std::endl;
相关文章:
- 试图让变量检查数组中的某些内容
- 如何在C++中检查2D数组中负值的输入验证
- 使用for循环检查数组中的重复项
- 检查TCHAR数组输入是否为带符号整数C++
- std::数组边界检查如何工作?
- 检查输入 std::array 指针数据是否等于某个常量数组
- 给定一个大小为 N 的数组 S,检查是否可以将序列拆分为两个序列
- C++ 检查结果数组中有多少次数字
- 检查数组中是否有字符串中的值,如果没有,则添加它
- 有没有办法在c ++中清除空数组,请检查下面的代码以获取说明
- 如何检查一个字符是否与字符数组中的另一个字符匹配?
- 如何检查二维数组上的周围数字?
- 检查反向数组是否与原始数组相同
- 如何检查cin是否与数组中的一组数字匹配
- 如何检查数组中是否没有值
- 如何检查字节数组是protobuf序列化字节数组还是普通字节数组
- 检查彩虹数组(检查数组的反向样式是否与自身匹配)
- 使用数组检查连续性
- c++ 根据随机生成的数组检查用户输入的值
- 使用字符串数组检查用户输入