[!!!!]关于统计于排序的一些小小挫折,有人可以告诉我思路吗???~
xid-2079983_1.pdf
(260.63 KB)
这是我的作业要求,就是有一份学生的成绩数据存入在file里,格式是:学生号,考试1成绩,考试2成绩,考试3成绩,考试4成绩, 我们的要求是把这些数据存入,然后统计出各个考试在0-9,10-19。。。。。90-100区间里的次数是多少,然后最后选其中一个考试从大到小排序。下面是数据和目前为止我写的程序。我的QQ 746942947,请各位告诉我哪里可以改正!!谢谢!!
#include<stdio.h>
#include<math.h>
typedef struct{
int result[5];
}student;
student st_r[40];
int main (void)
{
FILE *my_in;
int a =0,count[50][50],
b =0,number,j,num_stu,num[100];
float sum = 0,average, data;
char i,ch;
printf("\n\nProgram to display the four exam's results of students");
my_in = fopen ("U:\\datafile.txt","r");
if (my_in == NULL)
{
printf("\nError opening input file, program exiting\n");
printf("\nType a number & press the enter key to finish");
scanf("%d",&a);
return(1);
}
printf("\nProgram reading data from file\n");
while (fscanf(my_in,"%d,",&number)!=EOF)
{
st_r[b].result[a] = number;
a++;
if (a==5)
{
a= 0;
b++;
}
}
printf("\nPLJ b contains %d \n",b);
num_stu = b;
for(b = 0; b < num_stu; b++)
{
for(a= 0; a < 5; a++)
{
printf("%d,", st_r[b].result[a]);
}
printf("\n");
}
while(!feof(my_in))
{
ch=fgetc(my_in);
for ( i='0';i<='9';++i)
{
if (ch/10==i) num[i]++;
}
}
for ( i='0';i<='9';++i)
{
printf("%d,",num[i-'0']);
}
printf("\n");
//printf("\n0-9 %d\n10-19 %d\n20-29 %d \n30-39 %d\n40-49\ %dn50-59 %d\n60-69%d \n70-79%d \n80-89 %d\n90-100%d",count[0][a-1],count[1][a-1],count[2][a-1],count[3][a-1],count[4][a-1],count[5][a-1],count[6][a-1],count[7][a-1],count[8][a-1],count[9][a-1][7],count[a-1][8],count[a-1][9]);
printf("\n\n");
fclose(my_in);
printf("\nProgram complete.");
printf("\nType a number & press the enter key to finish");
scanf("%d",&a);
return(0);
}
这个是数据
105683,23,65,0,100
105475,96,72,35,61
105286,23,45,15,86
104762,23,17,5,56