這個程序算是用指針寫的嗎?
#include<stdlib.h>void main()
{
struct grade
{
int C;
char name[20];
char course[20];
int score;
char degree;
int no;
};
struct grade *student;
int i;
int num;
char degree[][10] = {"不及格", "及格", "中等", "良好", "优秀"};
int statistics[5] = {0};
int distribution[11] = {0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 4};
float sum = 0.0;
printf("请输入学生人数 ==>");
scanf("%d",&num);
student=(struct grade *)malloc(num *sizeof(struct grade));
if(!student)
{
printf("内存分配失败 !\n");
exit(1);
}
for(i=0;i<num;i++)
{
//printf("学生编号: %d\n",i + 1);
printf("请输入学生编号. ==> ");
scanf("%s",&student[i].no);
printf("请输入学生姓名. ==> ");
scanf("%s",&student[i].name[i]);
printf("请输入你要查询的课程. ==> ");
scanf("%s",&student[i].course );
printf("请输入成绩. ==> ");
scanf("%d",&student[i].C);
}
for (i = 0; i < num; i++)
{
sum += student[i].C;
}
printf("\n平均分:%.2f\n\n", sum / num);
for (i = 0; i < num; i++)
statistics[distribution[(int)(student[i].C / 10)]]++;
printf("等级统计:\n");
for (i = 0; i < 5; i++)
printf("%s:\t%d人\t%.1f%%\n", degree[i], statistics[i], 100 * (float)statistics[i]/num);
}