2 回答
TA贡献71条经验 获得超14个赞
#include<stdio.h>
#define N 40
int ReadScore(int score[],long num[]);
void DataSort(int score[],long num[],int n);
void printfscore(int score[],long num[],int n);
int main()
{
int n,score[N];
long num[N];
ReadScore(score,num);
printf("Total students'ID and students are %d\n",num,n);
DataSort(score,num,n);
printf("Sorted score:");
printfscore(score,num,n);
return 0;
}
int ReadScore(int score[],long num[])
{
int i=-1;
do
{
i++;
printf("Input students'ID and score:");
scanf("%ld%d",&num[i],&score[i]);
}while(score[i]>=0&&num[i]>0);
return i;
}
void DataSort(int score[],long num[],int n)
{
int i,j,k;
int temp1;
long temp2;
for(i=0;i<n-1;i++)
{
k=i;
for(j=i+1;j<n;j++)
{
k=j;
}
if(k!=1)
{
temp1=score[k];score[i]=score[k];score[i]=temp1;
temp2=num[k];num[k]=num[j];num[j]=temp2;
}
}
}
void printfscore(int score[],long num[],int n)
{
int i;
for(i=1;i<n;i++)
{
printf("%ld%d\n",num[i],score[i]);
}
printf("\n");
}
- 2 回答
- 0 关注
- 1950 浏览
添加回答
举报