c加加在三行四列数组中找第一个负数

c加加在三行四列数组中找第一个负数

代码如下:

#include <iostream>

using namespace std;

int main()
{
int numbers[3][4] = {
{ 45, 25, 96, 12 },
{ 96,-36, 25, 63 },
{ 52, 45, 86,-67 }
};

int n = 0, i, j;

for (i = 0; i < 3; i++) {
for (j = 0; j < 4; j++) {
if (numbers[i][j] < 0) {
n = numbers[i][j];
break;
}
}

if (n < 0) {
break;
}
}

cout << "第一个负数为:" << n << endl;

system("pause");
return 0;
}

运行结果:

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网