我該如何編寫一個函數來合併二維數組中的每一行的內容?要添加每列的內容? 我的代碼(到目前爲止):如何合併二維數組的行(和列)
#include <iostream>
using namespace std;
const int QUARTER = 4;
void getdata(float [][QUARTER], int);
void displaydata (float [][QUARTER], int);
void quartertotal(float [][QUARTER], int);
int main()
{
const int DIVISION = 6;
float data[DIVISION][QUARTER] = {0};
float getarray[DIVISION][QUARTER];
for (int a=0; a < DIVISION; a++)
{
for (int b = 0; b< QUARTER; b++)
{
cout << "Enter sales for Division ";
cout<< a+1;
cout<< " Quarter ";
cout<< b+1;
cout<< ": ";
cin >> getarray[a][b];
}
}
displaydata(getarray, DIVISION);
cout << endl;
quartertotal(getarray,DIVISION);
cout << endl;
cout << endl << endl;
return 0;
}
(float getarray[][QUARTER], int divisions)
{
cout<<"\t\t\t\tQ1\tQ2\tQ3\tQ4\n";
for (int i = 0; i < divisions; i++)
{
cout << "Sales for Division " << (i+1) << " are: \t";
for (int j=0; j < QUARTER; j++)
cout << getarray[i][j] << "\t";
cout << endl;
}
}
請更好地格式化代碼。 – PeterK 2010-07-13 20:57:34
我真的不知道如何...我花了一些時間嘗試格式化,但由於某種原因,網站不讓我 – mokwi8 2010-07-13 21:01:05
什麼是'(float getarray [] [QUARTER],int divisions)'應該是? – Jacob 2010-07-13 21:08:17