大家帮我看下面的C语言应该怎样修改啊?

来源:百度知道 编辑:UC知道 时间:2024/05/23 20:31:06
#include<stdio.h>
#include<stdlib.h>
void getrand(int *a)
{int i,j;
for(i=0;i<5;i++)
{for(j=0;j<=3;j++)
{a[i][j]=rand( )%101;
printf("%d",a[i][j]);}
}
}
void getsord(int *a,int*b)
{int i,j,s=0,t,max;
for(i=0;i<=4;i++)
{for(j=0;j<=3;j++)
{t=a[i][j];
s=t+s;
b[i]=s;
}
max=b[0];
for(i=1;i<5;i++)
{if(max<b[i])
max=b[i];
}
}
shuchu(int *a,int *b)
{int i,j;
for(i=0;i<5;i++)
{for(j=0;j<4;j++)
printf("%d",a[i][j]);
printf("%d",b[i]);
}
main( )
{int a[5][4],b[5];
getrand(a);
getsord(a,b);
shuchu(a,b);
}
------------------Configuration: fsdfsdf - Win32 Debug--------------------
Compiling...
fdgfgfg.cpp
d:\vc6.0\msdev98\myprojects\fsdfsdf\fdgfgfg.cpp(7) : error C2109: subscript requires array or pointer type

应该改成这样:
需要注意的是在getsord函数里少了一个大括号
二维数组传值的时候需要知道第二维的上界

#include<stdio.h>
#include<stdlib.h>
void getrand(int a[][4])
{
int i,j;
for(i=0;i<5;i++)
{
for(j=0;j<=3;j++)
{
a[i][j]=rand( )%101;
a[i][j] = 0;
printf("%d",a[i][j]);
}
}
}
void getsord(int a[][4],int *b)
{
int i,j,s=0,t,max;
for(i=0;i<=4;i++)
{
for(j=0;j<=3;j++)
{
t=a[i][j];
s=t+s;
b[i]=s;
}
max=b[0];
for(i=1;i<5;i++)
{
if(max<b[i])
max=b[i];
}
}
}
void shuchu(int a[][4],int *b)
{
int i,j;
for(i=0;i<5;i++)
{
for(j=0;j<4;j++)
printf("%d",a[i][j]);
printf("%d",b[i]);
}
}
int main()
{
int a[5][4],b[5];
getrand(a);
getsord(a,b);
shuchu(a