谁能帮忙解释下下面的程序 急!~

来源:百度知道 编辑:UC知道 时间:2024/05/15 07:51:17
#include <stdio.h>
#include <string.h>
#define N 25
struct student
{ char name[25]; //结构中使用数组存储学生姓名。
int score;
};

void main()
{ int i,j,k,order=0;
struct student p[N],temp;
char name[25]; //使用数组存储输入的名字的字符串
for(i=0;i<N;i++)
{
flushall();
printf("Please Input Name: ");
scanf("%s",p[i].name);
printf("Please Input Score:",p[i].name); //输入姓名和分数
scanf("%d",&p[i].score);
}
gets(name); //此句用来消除后面的输入学生姓名的影响
for(i=0;i<N-1;i++)
{
k=i;
for(j=i+1;j<N;j++)
if(p[j].score<p[k].score) k=j;
temp=p[i];
p[i]=p[k];
p[k]=temp;
}
printf("\n***********Order Table**********\n");
printf("\nNo Name Score\n");
for(i=0;i<N;i++)
printf("%-6d%-15s%6d\n",i+1,p[i].name,p[i].score); //显示排

这是个“学生成绩表”,是C语言写的,
先输入姓名和成绩,
在从高到低排序,
最后输出个成绩排行榜,
最最后可以查询某个学生的成绩。

你的有错误,我基本重新写了个:
====================================================================
#include <stdio.h> /* 输入输出,要引入头文件 stdio.h */
#include <string.h> /* 处理字符串,要引入头文件 string.h */

#define N 25 /* 将来创建 N 个 '存储单位' */

struct student /* 定义结构体 student 用来做 '存储单位' */
{char name[8]; /* student.name[8] 用于存储学生姓名 */
int score; /* student.score 用于存储学生成绩 */
};

void main()
{int i,j;

struct student p[N],temp;
/* 创建 '由 N 个 student 组成的数组 p' 和 '一个 student 中间变量 temp' */

char name[8];

for(i=0;i<N;i++)
{
flushall(); /* (C语言自带函数)清除所有缓冲区 */

print("Please Input Name:"); /* 输入姓名 */
gets(p[i].name);
print("Please Input %s's Score:",p[i].name); /* 输入与姓名对应的分数 */
scanf("%d",&p[i].score)