新手求助一维数组转换为二维数组
#include"stdio.h"int sum(int a[][2],int row,int column);
int main()
{
int i,j;
static int k;
int a[10000][2];
int a1[20000];
int row,column;
int total;
char ch;
int count=0;
printf("Input the number to array:\n");
for(i=0;i<20000;i++)
{
scanf("%d",&a1[i]);
ch=getchar();
count++;
if(ch=='\n')
break;
}
column=3;
row=count/column;
for(i=0;i<row;i++)
for(j=0,k=0;j<column;j++,k++) //error
a[i][j]=a1[k];
// printf("%d\n",element);
// printf("%d %d\n",row,column);
total=sum(a,row,column);
printf("sum of the array is %d\n",total);
for(i=0;i<row;i++)
{
for(j=0;j<column;j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
}
int sum(int a[][2],int row,int column)
{
int i,j;
int sum=0;
for(i=0;i<row;i++)
for(j=0;j<column;j++)
sum+=a[i][j];
return sum;
}