这是程序的输出:如何获得一个数组来计算有多少个数字,而不是统计每个数字的值?
*** start of 276 2D Arrays_03.cpp program ***
Number Count Total
1 3 3
2 6 9
3 15 24
4 6 30
5 9 39
*** end of 276 2D Arrays_03.cpp program ***
这是代码:
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
const int COLUMN_SIZE = 13;
int main(void)
{
const int ROW_SIZE = 3;
const int COUNT_SIZE = 5;
void countValues(const int[][COLUMN_SIZE], const int, int[]);
void display(const int [], const int);
int numbers[ROW_SIZE][COLUMN_SIZE] = {{1, 3, 4, 5, 3, 2, 3, 5, 3, 4, 5, 3, 2},
{2, 1, 3, 4, 5, 3, 2, 3, 5, 3, 4, 5, 3},
{3, 4, 5, 3, 2, 1, 3, 4, 5, 3, 2, 3, 5}};
int counts[COUNT_SIZE] = {0};
string choice;
cout << "*** start of 276 2D Arrays_03.cpp program ***" << endl;
cout << endl;
countValues(numbers, ROW_SIZE, counts);
display(counts, COUNT_SIZE);
cout << endl;
cout << endl;
cout << "*** end of 276 2D Arrays_03.cpp program ***" << endl << endl;
cin.get();
return 0;
} // end main()
这是我需要计数的每个值的功能。我知道如何对行和列进行求和,但我不太清楚代码是否能够自己计算值。
void countValues(const int numbers[][COLUMN_SIZE], const int ROW_SIZE, int counts[])
这是我到目前为止。
{
for (int index = 0; index < ROW_SIZE; index++)
counts[index];
{
这是功课?格林威治标准时间午夜如何突然出现家庭作业?嗯...... –
是的,但是直到下周才推出,只是想把它弄明白。 –
到目前为止您尝试过什么?它可以帮助我们(和你)向我们展示你有多远以及你正在采取什么方法。 – M3NTA7