qmh_c 于 2015.07.08 01:23 提问

9个回答

securitit   2015.07.08 08:17

1.对b数组求和
2.输出值=a数组当前元素*b数组个数+b数组的和

qq983796981   2015.07.08 04:19

#include
int main()
{int a[ ]={1,2,3,4,5},b[ ]={1,2,3,4,5};
int x=sizeof(a)/sizeof(a[0]), y=sizeof(b)/sizeof(b[0]);
int i,j;int c[y],sum=0;
for(i=0;i<x;i++)
{ printf("c(%d)=",i);

for(j=0;j<y;j++)

{ c[j]=a[i]+b[j];

sum=sum+c[j];

printf("%d ",c[j]);

}
printf("\n sum(%d)=%d \n",i,sum);
}

return 0;
}

fengyehudie   2015.07.08 08:23

strutce      2015.07.08 09:08

#include
int main()
{int a[ ]={1,2,3,4,5},b[ ]={1,2,3,4,5};

int i,j;sum=0;sum1=0;
for(i=0;i<b.length;i++)
{sum+=b[i];
}
for(j=0;j<a.length;j++)
{
sum1=sum+a[i]*b.length;
printf(sum1);
}

}

lovelj2012   2015.07.08 09:52

a数组每个元素要依次和b数组逐个元素相加，那么可以先把b数组各元素求和保存到一个变量

frank_20080215   2015.07.08 11:20

int a[ ]={1,2,3,4,5};
int b[ ]={1,2,3,4,5};
int size = sizeof(a)/sizeof(a[0]);
int sum[ ] = {};
int i,j;

sum[size] = {0,0,0,0,0}

for (i = 0; i < size; i++){
for (j = 0; j < size; j++) {
b[j] = b[j] + a[i];
}
for(j = 0; j < size; j++){
sum[i] = sum[i] + b[j];
}
}

zt110120   2015.07.09 15:02

#include

int main()
{
int i,j;
int sum = 0;
int a[] = {1,2,3,4,5,};
int b[] = {1,2,3,4,5};
int c[6] = {0};

``````for(i = 0;i < 5;i++)
{
for(j = 0;j < 5;j++)
{
c[j] = a[i] + b[j];
sum= sum + c[j];
}
printf("%d\n",sum);
sum = 0;
}
return 0;
``````

}

u014306011   2015.07.14 12:27

`````` #include<stdio.h>
int main(){
int i,j,sum;
int a[]={1,2,3,4,5};
int b[]={1,2,3,4,5};
int c[]={0,0,0,0,0};
for(i=0;i<5;i++){
sum=0;
for(j=0;j<5;j++){
c[j]=a[i]+b[j];
sum+=c[j];
}
for(j=0;j<5;j++)
if(j!=4)
printf("%d+",c[j]);
else
printf("%d=",c[j]);
printf("%d\n",sum);
}
return 0;
}

``````
lingzhu111   2015.08.07 17:02

b 的每个元素为 b[i] + a[0] + a[1] .... + a[4]

b[1] + a[0] + a[1] .... + a[4]
b[2] + a[0] + a[1] .... + a[4]
b[3] + a[0] + a[1] .... + a[4]
b[4] + a[0] + a[1] .... + a[4]

``````             sum(b[]) + 5*sum(a[])
``````