C++编程,求二维数组所有元素的和
2个回答
展开全部
int SunMatrix(int *matrix[],int Column,int Line) //假设列数为Column 行数Line
{
int sum=0;
for(int i=0;i<Line;i++)
for(int j=0;j<Column;j++)
sum+=matrix[i][j];
return sum;
}
更多追问追答
追问
这i和j和能加在一起么?
追答
你的意思是只写一个循环?
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2019-10-28
展开全部
#include <iostream>
using namespace std;
const int year = 3;
const int month = 12;
int main(int argc,char **argv)
{
int sales[year][month];
int o_total [3] = {0};
int t_total = 0;
for(int i=0;i<year;i++)
{
for(int j=0;j<month;j++)
{
cout<<"year "<<i+1<<" "<<j+1<<" month ";
cin>>sales[i][j];
o_total[i] += sales[i][j];
t_total += sales[i][j];
}
//t_total += sales[i][j];
cout<<"year "<<i+1<<" "<<o_total[i]<<endl;
}
cout<<"total of year"<<t_total<<endl;
}
using namespace std;
const int year = 3;
const int month = 12;
int main(int argc,char **argv)
{
int sales[year][month];
int o_total [3] = {0};
int t_total = 0;
for(int i=0;i<year;i++)
{
for(int j=0;j<month;j++)
{
cout<<"year "<<i+1<<" "<<j+1<<" month ";
cin>>sales[i][j];
o_total[i] += sales[i][j];
t_total += sales[i][j];
}
//t_total += sales[i][j];
cout<<"year "<<i+1<<" "<<o_total[i]<<endl;
}
cout<<"total of year"<<t_total<<endl;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询