C语言函数间传输二维数组的问题。
#include<stdio.h>intscore[30][2],p,sum=0;voidAppend();voidToave(intscore[]);voidSortS...
# include <stdio.h>
int score[30][2],p,sum=0;
void Append();
void Toave(int score[]);
void SortScore(int number[],int score[]);
void SortNumber(int number[],int score[]);
void Sear(int number[],int score[]);
void Analysis(int number[],int score[]);
void List(int number[],int score[]);
int main()
{
int a;
while(1){
printf("1. Append record\n");
printf("2. Caculate total and average score of course\n");
printf("3. Sort in descending order by score\n");
printf("4. Sort in ascending order by number\n");
printf("5. Search by number\n");
printf("6. Statistic analysis\n");
printf("7. List record\n");
printf("0. Exit\n");
printf("Please enter your choice:");
scanf("%d",&a);
if(a==1)
{
Append();
}
if(a==2)
{
Toave(score);
}
if(a==3)
{
SortScore(score);
}
if(a==4)
{
SortNumber(score);
}
if(a==5)
{
Sear(score);
}
if(a==6)
{
Analysis(score);
}
if(a==7)
{
List(score);
}
if(a==0)
{
break;
}
}
return 0;
}
void Append()
{
int i;
printf("Please input the number of the students:");
scanf("%d",&p);
printf("Please input the ID and score of the students:\n");
for(i=0;i<p;i++)
{
scanf("%d %d",&score[i][i/2+1];
}
}
void Toave(int score[30][2])
{
int i;
for(i=0;i<p;i++)
{
sum=sum+score[i][2];
}
printf("Total score is %d.\n",sum);
printf("Average score is %d.\n",sum/p);
}
后面一部分不往上贴了- -好像是在函数间传输二维数组的时候格式有问题啊= =求大神 展开
int score[30][2],p,sum=0;
void Append();
void Toave(int score[]);
void SortScore(int number[],int score[]);
void SortNumber(int number[],int score[]);
void Sear(int number[],int score[]);
void Analysis(int number[],int score[]);
void List(int number[],int score[]);
int main()
{
int a;
while(1){
printf("1. Append record\n");
printf("2. Caculate total and average score of course\n");
printf("3. Sort in descending order by score\n");
printf("4. Sort in ascending order by number\n");
printf("5. Search by number\n");
printf("6. Statistic analysis\n");
printf("7. List record\n");
printf("0. Exit\n");
printf("Please enter your choice:");
scanf("%d",&a);
if(a==1)
{
Append();
}
if(a==2)
{
Toave(score);
}
if(a==3)
{
SortScore(score);
}
if(a==4)
{
SortNumber(score);
}
if(a==5)
{
Sear(score);
}
if(a==6)
{
Analysis(score);
}
if(a==7)
{
List(score);
}
if(a==0)
{
break;
}
}
return 0;
}
void Append()
{
int i;
printf("Please input the number of the students:");
scanf("%d",&p);
printf("Please input the ID and score of the students:\n");
for(i=0;i<p;i++)
{
scanf("%d %d",&score[i][i/2+1];
}
}
void Toave(int score[30][2])
{
int i;
for(i=0;i<p;i++)
{
sum=sum+score[i][2];
}
printf("Total score is %d.\n",sum);
printf("Average score is %d.\n",sum/p);
}
后面一部分不往上贴了- -好像是在函数间传输二维数组的时候格式有问题啊= =求大神 展开
1个回答
展开全部
# include <stdio.h>
int score[30][2],p,sum=0;
void Append();
void Toave(int score[]);
void SortScore(int number[],int score[]);
void SortNumber(int number[],int score[]);
void Sear(int number[],int score[]);
void Analysis(int number[],int score[]);
void List(int number[],int score[]);
int main()
{
int a;
while(1){
printf("1. Append record\n");
printf("2. Caculate total and average score of course\n");
printf("3. Sort in descending order by score\n");
printf("4. Sort in ascending order by number\n");
printf("5. Search by number\n");
printf("6. Statistic analysis\n");
printf("7. List record\n");
printf("0. Exit\n");
printf("Please enter your choice:");
scanf("%d",&a);
if(a==1)
{
Append();
}
if(a==2)
{
Toave(score);
}
if(a==3)
{
SortScore(score);
}
if(a==4)
{
SortNumber(score);
}
if(a==5)
{
Sear(score);
}
if(a==6)
{
Analysis(score);
}
if(a==7)
{
List(score);
}
if(a==0)
{
break;
}
}
return 0;
}
void Append()
{
int i;
printf("Please input the number of the students:");
scanf("%d",&p);
printf("Please input the ID and score of the students:\n");
for(i=0;i<p;i++)
{
scanf("%d %d",&score[i][i/2+1]; //i/2+1是什么意思
}
}
void Toave() //这里不要参数,因为score[30][2]是全局变量。
{
int i;
for(i=0;i<p;i++)
{
sum=sum+score[i][2]; //这个错误,第二维数组是0,1,没有2哦
}
printf("Total score is %d.\n",sum);
printf("Average score is %d.\n",sum/p);
}
int score[30][2],p,sum=0;
void Append();
void Toave(int score[]);
void SortScore(int number[],int score[]);
void SortNumber(int number[],int score[]);
void Sear(int number[],int score[]);
void Analysis(int number[],int score[]);
void List(int number[],int score[]);
int main()
{
int a;
while(1){
printf("1. Append record\n");
printf("2. Caculate total and average score of course\n");
printf("3. Sort in descending order by score\n");
printf("4. Sort in ascending order by number\n");
printf("5. Search by number\n");
printf("6. Statistic analysis\n");
printf("7. List record\n");
printf("0. Exit\n");
printf("Please enter your choice:");
scanf("%d",&a);
if(a==1)
{
Append();
}
if(a==2)
{
Toave(score);
}
if(a==3)
{
SortScore(score);
}
if(a==4)
{
SortNumber(score);
}
if(a==5)
{
Sear(score);
}
if(a==6)
{
Analysis(score);
}
if(a==7)
{
List(score);
}
if(a==0)
{
break;
}
}
return 0;
}
void Append()
{
int i;
printf("Please input the number of the students:");
scanf("%d",&p);
printf("Please input the ID and score of the students:\n");
for(i=0;i<p;i++)
{
scanf("%d %d",&score[i][i/2+1]; //i/2+1是什么意思
}
}
void Toave() //这里不要参数,因为score[30][2]是全局变量。
{
int i;
for(i=0;i<p;i++)
{
sum=sum+score[i][2]; //这个错误,第二维数组是0,1,没有2哦
}
printf("Total score is %d.\n",sum);
printf("Average score is %d.\n",sum/p);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询