找到二維矢量的總和有些麻煩。這看起來好嗎?查找二維矢量的總和
int sumOfElements(vector<iniMatrix> &theBlocks)
{
int theSum = 0;
for(unsigned i=0; (i < theBlocks.size()); i++)
{
for(unsigned j=0; (j < theBlocks[i].size()); j++)
{
theSum +=theBlocks[i][j];
}
}
return theSum;
}
它返回一個負數,但是,它應該返回正數..
希望有人能幫助:)
什麼是'iniMatrix',你期望結果符合一個有符號的int – 2012-08-17 02:07:54
矩陣的所有元素都是正的嗎? – dasblinkenlight 2012-08-17 02:08:14
嘿,不是所有的值都是正值,但是,我正在使用的算法中的for循環。 @dasblinkenlight – Phorce 2012-08-17 02:38:38