這是程序的輸出:如何獲得一個數組來計算有多少個數字,而不是統計每個數字的值?
*** 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