一维数组的赋值函数调用
#include<stdio.h>#define N 30 //人数
int ReadScore(int score[],long num[],int n); //输入数
void StudScore(int score[],char Grade[],int n); //学生成绩及等级
void AverforCourse(int score[],int sum[],float aver[],int n); //课程总分及平均成绩
void Print(int score[],long num[],char Grade[],int sum[],float aver[],int n); //按学号输出成绩及等级
int BinSearch(int score[],long num[],long x,int n); //查找序号分数
void SortScore(int score[],long num[],int n); //按成绩减小排序
void SortNum(int score[],long num[],int n); //按学号增大排序
void PrintScore(int score[],long num[],int n); //输出按成绩排序的数组
int main()
{
int score[N],sum[N],n,i;
char Grade[5],op,oq;
long num[N],x;
float aver[N];
printf("Input the total number of the students(n<=30):");
scanf("%d",&n);
ReadScore(score,num,n); //输入数
AverforCourse(score,sum,aver,n); //计算课程总分及平均成绩
for(i = 1;;i++)
{
printf("选择用序号增大的形式还是用成绩减小的形式输出成绩(N or S):");
scanf(" %c",&oq);
if(oq != 'S')
{
SortNum(score,num,n); //按学号大小排序
Print(score,num,Grade,sum,aver,n); //按学号输出成绩等级
}
printf("是否还要按照成绩减小的形式输出(Y or N)?\n");
scanf(" %c",&oq);
if(oq != 'N')
{
SortScore(score,num,n); //按成绩大小排序
PrintScore(score,num,n); //按成绩输出成绩等级
break;
}
else break;
}
for(i = 1;;i++)
{
printf("Do you want to search for someone?(Anykey or N)");
scanf(" %c",&op);
if(op != 'N')
BinSearch(score,num,x,n);
else break;
}
}
int ReadScore(int score[],long num[],int n) //输入数
{
int i,j;
printf("Input student's ID and scores:\n");
for(i = 0;i<n;i++)
{
scanf("%ld%d",&num[i],&score[i]);
}
}
void AverforCourse(int score[],int sum[],float aver[],int n) //计算学科总分和平均分
{
int i,p;
p = 0;
for(i = 0;i<n;i++)
{
p = p+score[i];
}
sum[i] = p;
aver[i] = (float)sum[i]/n;
}
void Print(int score[],long num[],char Grade[],int sum[],float aver[],int n) //按学号排序
{
int i,a = 0,b = 0,c =0,d = 0,e = 0;
printf("Sort in numbers:\n");
printf("Student's ID\t Scores\tGrade\n");
for(i = 0;i<n;i++)
{
if(score[i]>=90&&score[i]<=100) Grade[i] = 'A',a++;
if(score[i]>=80&&score[i]<=89) Grade[i] = 'B',b++;
if(score[i]>=70&&score[i]<=79) Grade[i] = 'C',c++;
if(score[i]>=60&&score[i]<=69) Grade[i] = 'D',d++;
if(score[i]>=0&&score[i]<=59) Grade[i] = 'E',e++;
printf("%12ld\t%8d\t %c\n",num[i],score[i],Grade[i]);
}
printf("SumofCourse\t%4d\t",sum[i]);
printf("\nAverofcourse\t%4.1f\t",aver[n]);
printf("\nThe number of A:%d,The percent of A:%3.2f%%",a,(float)a/n*100);
printf("\nThe number of B:%d,The percent of B:%3.2f%%",b,(float)b/n*100);
printf("\nThe number of C:%d,The percent of C:%3.2f%%",c,(float)c/n*100);
printf("\nThe number of D:%d,The percent of D:%3.2f%%",d,(float)d/n*100);
printf("\nThe number of E:%d,The percent of E:%3.2f%%",e,(float)e/n*100);
printf("\n");
}
int BinSearch(int score[],long num[],long x,int n) //查找函数
{
int i,p,k = 1;
char op;
printf("Student's number:");
scanf("%ld",&x);
for(i = 0;i<n;i++)
{
if(x == num[i])
{
printf("%d\t",score[i]);
p = score[i];
}
}
for(i = 0;i<n;i++)
{
if(score[i]>p)
k++;
}
printf("名次是:%d\n",k);
}
void SortNum(int score[],long num[],int n) //按学号大小排序
{
int i,j,k,temp2;
long temp1;
for(i = 0;i<n-1;i++)
{
k = i;
for(j = i+1;j<n;j++)
{
if(num[j]<num[k])
{
k = j;
}
}
if(k!=i)
{
temp1 = num[k];num[k] = num[i];num[i] = temp1;
temp2 = score[k];score[k] = score[i];score[i] = temp2;
}
}
}
void SortScore(int score[],long num[],int n) //按成绩大小排序
{
int i,j,k,temp1;
long temp2;
for(i = 0;i<n-1;i++)
{
k = i;
for(j = i+1;j<n;j++)
{
if(score[j]>score[k])
{
k = j;
}
}
if(k!=i)
{
temp1 = score[k];score[k] = score[i];score[i] = temp1;
temp2 = num[k];num[k] = num[i];num[i] = temp2;
}
}
}
void PrintScore(int score[],long num[],int n) //按成绩排序
{
int i;
printf("Student's Scores\tID\tGrade\n");
for(i = 0;i<n;i++)
{
printf("%12ld\t%12d\n",score[i],num[i]);
}
}
这个问题就是..会输出好多0,最后程序崩溃.....
求解答..有点长请各位大神理解.....