我正在尝试使我的 2-D 数组程序获取每行中最大的元素,但它不起作用
I'm trying to make my 2-D Array program to get the largest element in each row but its not working
这是我的代码
#include <iostream>
using namespace std;
const int rows = 2;
const int cols = 6;
void CheckRow(int x[][6], int rows){
int highestr = 0;
int r = 0, c = 0;
for (r = 0; r < rows; ++r){
cout << "ROW " << r + 1 << ": ";
for (c = 0; c < cols; ++c)
cout << x[r][c] << " ";
cout << endl;
}
> End of PRINTING THE CONTENTS
> THE CODE BELOW MUST CHECK FOR THE GREATEST VALUE IN A ROW, BUT IT WONT GIVE ME THE EXACT RESULTS AS IT SHOULD DISPLAY
for (r = 0; r < rows; ++r){
for (c = 0; c < cols; ++c)
if (x[r][c] > highestr){
highestr += x[r][c];
cout << " Greatest Number: " << highestr;
cout << endl;
}
}
}
int main()
{
int temps[rows][cols] =
{
{ 12, 13, 14, 15, 16, 17 },
{ 18, 19, 20, 21, 22, 23 }
};
CheckRow(temps, 2);
cout << endl << endl;
system("pause");
return 0;
}
for (r = 0; r < rows; ++r)
{
for (c = 0; c < cols; ++c)
{
if (x[r][c] > highestr)
{
highestr = x[r][c];
}
}
cout << " Greatest Number: " << highestr;
cout << endl;
highestr=0; // considering every element in your 2D array is greater than 0
}
相关文章:
- 为什么使用数组元素查找最大数字的程序不起作用?
- C++ 函数,用于查找数组中四个最小最大元素的总和不起作用
- C++:矩阵高斯消除不起作用:使用单维数组来存储元素
- 从数组中删除元素不起作用的函数
- 双链接列表添加元素不起作用,不知何故它总是保持为空
- 如果 x,递归不起作用,我的函数只能删除第一个元素
- 尝试读取数据文件,存储在数组中并打印所有元素,但它不起作用
- 在C++中实现二叉搜索树,搜索不起作用.尝试打印节点的元素会导致输出崩溃
- 使用 std::move 在开始时插入矢量的中间元素不起作用
- 将列表元素移动到列表末尾的函数多次不起作用
- 如何通过长度从 std::vector 中删除元素<string>(擦除不起作用)
- 为什么此C 代码不起作用 - 试图删除集合中的元素时,请参考错误
- 当中间元素选择为枢轴时,快速排序C 不起作用
- 元素向量乘法 C++(代码不起作用)
- 在我试图创建一个载体中包含C 中的唯一元素的矢量时,发现不起作用
- 当通过引用传递时,通过传递链表在第n个位置添加元素不起作用
- 我正在尝试使我的 2-D 数组程序获取每行中最大的元素,但它不起作用
- 为什么当我放置偶数个元素时我的程序不起作用
- 运算符 类对象的重载在访问包含它的向量元素时不起作用
- 用于移动不起作用的数组元素的函数