//姓名    國文    英文    數學    總分    平均    名次
//甲      70      60      65      195     65       4
//乙      80      76      90      246     82       1
//丙      75      65      90      230     77       2
//丁      56      80      70      206     69       3
//--------------------這是分割線----------------------
//姓名    國文    英文    數學    總分    平均    名次
//甲      70      60      65      195     65       4
//乙      80      76      90      246     82       1
//丙      75      65      90      230     77       2
//丁      56      80      70      206     69       3
//
#include
#include
#include
#include
int main (int argc, char argv[])
{
	int StudentScores[10][6];
	char StudentName[10][20];
	int Cur=0;
	int Index=0;
	FILE *fp=NULL;
	fp = fopen("Scores.txt","rb");
		if (fp==NULL)
			return -1;
		for(Cur=0; Cur<4;Cur++) { fscanf(fp,"%s\t%d\t%d\t%d\t%d\t%d\t%d",StudentName[Cur],&StudentScores[Cur][0],&StudentScores[Cur][1], &StudentScores[Cur][2],&StudentScores[Cur][3],&StudentScores[Cur][4]); //StudentScores[Cur][4]=(StudentScores[Cur][0]+StudentScores[Cur][1]+StudentScores[Cur][2])/3; } fclose(fp); printf("\n姓名\t國文\t英文\t數學\t總分\t平均\t名次\r\n"); for(Cur=0;Cur<4;Cur++) { StudentScores[Cur][3]=StudentScores[Cur][0]+StudentScores[Cur][1]+StudentScores[Cur][2]; StudentScores[Cur][4]=(StudentScores[Cur][0]+StudentScores[Cur][1]+StudentScores[Cur][2])/3; printf("%s\t%2d\t%2d\t%2d\t%d\t%d\t%d \r\n", StudentName[Cur],StudentScores[Cur][0],StudentScores[Cur][1], StudentScores[Cur][2],StudentScores[Cur][3],StudentScores[Cur][4],Cur+1); } printf("\n--------------------這是分割線----------------------"); //seqencing int temp_Scores[6]; char temp_Name[20]; int i=0,j=0; int value=0; for(i=0;i<4;i++) { for(j=i+1;j<4;j++) { if(StudentScores[j][3]>StudentScores[i][3])
				{
					memcpy(temp_Scores,StudentScores[j],sizeof(temp_Scores));
					memcpy(StudentScores[j],StudentScores[i],sizeof(temp_Scores));
					memcpy(StudentScores[i],temp_Scores,sizeof(temp_Scores));
					
					memcpy(temp_Name,StudentName[j],sizeof(temp_Name));
					memcpy(StudentName[j],StudentName[i],sizeof(temp_Name));
					memcpy(StudentName[i],temp_Name,sizeof(temp_Name));
				}
			}
		}
		printf("\r\n\n姓名\t國文\t英文\t數學\t總分\t平均\t名次\r\n");
		
		for(Cur=0;Cur<4;Cur++) { //StudentScores[Cur][3]=StudentScores[Cur][0]+StudentScores[Cur][1]+StudentScores[Cur][2]; //StudentScores[Cur][4]=(StudentScores[Cur][0]+StudentScores[Cur][1]+StudentScores[Cur][2])/3; printf("%s\t%2d\t%2d\t%2d\t%d\t%d\t%d\r\n", StudentName[Cur],StudentScores[Cur][0],StudentScores[Cur][1], StudentScores[Cur][2],StudentScores[Cur][3],StudentScores[Cur][4],Cur+1); } return 0; }