大一新生 CS专业 自己提前学到数组这里 做了道题 出现错误 求指点
#include<stdio.h>#define MAX_NUMBER 30
void ReadSco( long num[], int sco[], int n);
void CacuSco(int n);
void RankSco( long num[], int sco[], int n);
main()
{
int n;
long num;
int sco;
printf("Input n:\n");
scanf("%d",&n);
ReadSco(num,sco,n);
CacuSco(n);
RankSco(num,sco,n);
}
void ReadSco( long num[], int sco[], int n)
{
int i;
printf("Input record:\n");
for( i=0; i<n; i++)
{
scanf("%ld%d\n",&num[i],&sco[i]);
}
}
void CacuSco(int sco[], int n)
{
int i;
int sum;
float average;
printf("Caculate total and average score of course:\n");
for ( i=0; i<n; i++ )
{
sum += sco[i];
}
average =(float)sum/n;
printf("%d%f\n",sum,average);
}
void RankSco( long num[], int sco[], int n)
{
int i,j,temp;
for ( i=0; i<n-1; i++ )
{
for( j=i+i; j<n; j++ )
{
if ( num[j] > num[i] )
{
temp = num[j];
num[j] = num[i];
num[i] = temp;
}
if ( sco[j] < sco[i] )
{
temp = sco[i];
sco[j] = sco[i];
sco[i] = temp;
}
}
}
printf("%ld\t%d\n",num[i],sco[i]);
}
如图按回车就错误.