2个回答
展开全部
考虑到这道题的性质,用一维数组运算速度更快(原理就不说了,要想问再留言)
int arry1[5]={1,3,5,7,9};
int arry2[5]={2,4,6,8,10};
int arry3[5]={3,5,8,7,6};
int sum_row[3]={0*3};/*一行元素之和*/
int sum_column[5]={0*8};/*一列元素之和*/
for(int i=0;i<5;i++)
{
sum_row[0]+=arry1[i];
sum_row[1]+=arry2[i];
sum_row[2]+=arry3[i];
sum_column[i]=arry1[i]+arry2[i]+arry2[i];
printf("第%d列和为%d",i,sum_column[i]);
}
for(int i=0;i<3;i++)
{
printf("第%d行和为%d",i,sum_row[i]);
}
int arry1[5]={1,3,5,7,9};
int arry2[5]={2,4,6,8,10};
int arry3[5]={3,5,8,7,6};
int sum_row[3]={0*3};/*一行元素之和*/
int sum_column[5]={0*8};/*一列元素之和*/
for(int i=0;i<5;i++)
{
sum_row[0]+=arry1[i];
sum_row[1]+=arry2[i];
sum_row[2]+=arry3[i];
sum_column[i]=arry1[i]+arry2[i]+arry2[i];
printf("第%d列和为%d",i,sum_column[i]);
}
for(int i=0;i<3;i++)
{
printf("第%d行和为%d",i,sum_row[i]);
}
展开全部
#include <stdio.h>
void main(void)
{
int a[3][5] = {{1,3,5,7,9}, {2, 4, 6, 8, 10}, {3, 5, 8, 7, 6}};
int i, j, r_sum[3], c_sum[5];
for (i=0; i<3; i++)// 各行的和
{
r_sum[i] = 0;
for (j=0; j<5; j++)
{
r_sum[i] += a[i][j];
}
printf("第%d行的和为:%d\n", i, r_sum[i]);
}
for (j=0; j<5; j++)// 各列的和
{
c_sum[j] = 0;
for (i=0; i<3; i++)
{
c_sum[j] += a[i][j];
}
printf("第%d列的和为:%d\n", j, c_sum[j]);
}
}
void main(void)
{
int a[3][5] = {{1,3,5,7,9}, {2, 4, 6, 8, 10}, {3, 5, 8, 7, 6}};
int i, j, r_sum[3], c_sum[5];
for (i=0; i<3; i++)// 各行的和
{
r_sum[i] = 0;
for (j=0; j<5; j++)
{
r_sum[i] += a[i][j];
}
printf("第%d行的和为:%d\n", i, r_sum[i]);
}
for (j=0; j<5; j++)// 各列的和
{
c_sum[j] = 0;
for (i=0; i<3; i++)
{
c_sum[j] += a[i][j];
}
printf("第%d列的和为:%d\n", j, c_sum[j]);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询