某班有30个学生,进行数学考试,编写程序将考试成绩输一维数组,将数学成绩排序,由高到低顺序排序后输出

某班有30个学生,进行了数学考试,编写程序将考试成绩输入一维数组,并将数学成绩排序,由高到低的顺序排序后输出。

第1个回答  2014-05-16
#include<stdio.h>
void bubble(int *a,int n) ;
int main(void)
{
int StdNo = 30;
int MathValue[30] = {0};

printf("Please enter the math Values of the all students: \n");
for(int i = 0; i < StdNo; i++)
{
scanf("%d",&MathValue[i]);
}

bubble(MathValue,StdNo);

printf("Output the math values: \n");
for(int j = 0; j < StdNo; j++)
{
printf("%d ",MathValue[j]);
}

printf("\n");

return 0;

}

void bubble(int *a,int n) /*定义两个参数:数组首地址与数组大小*/

{

int i,j,temp;

for(i=0;i<n-1;i++)

for(j=i+1;j<n;j++) /*注意循环的上下限*/

if(a[i]<a[j]) {

temp=a[i];

a[i]=a[j];

a[j]=temp;

}

}本回答被提问者采纳