Most of the code according to the book, and their own changes to write some layout and data after the results are as follows
The program code is as follows
#include <stdio.h>
#include <string.h>
#include <windows.h>
#define N 4
void Gotoxy (int x, int y)//define Gotoxy function (to move the cursor to the specified position)
{
int xx=0x0b;
HANDLE Houtput;
COORD Loc;
Loc. x = x;
Loc. Y=y;
Houtput = GetStdHandle (Std_output_handle);
SetConsoleCursorPosition (Houtput, loc);
Return
}
int main ()
{
Char name[n][20],name_t[20];
int score[n][3],sum[n];
int i,j,t;
CLRSCR ();
printf ("*********************************************************\n*\t\t\t\t\t\t\t*\n*\t\t\t\t\t\t\t*\n");
printf ("*\t\t Please enter student name and score, return end \t\t*\n*\t\t\t\t\t\t\t*\n*\t\t\t\t\t\t\t*\n*************************************** \n\n\n ");
printf ("%-12s%-12s%-12s%-12s\n\n", "name", "Language", "Mathematics", "C language");
for (i=0;i<n;i++)
{
sum[i]=0;
Gotoxy (0,10+i);
scanf ("%s", &name[i]);
for (j=0;j<3;j++)
{
Gotoxy ((j+1) *12,10+i);
scanf ("%d", &score[i][j]);
SUM[I]=SUM[I]+SCORE[I][J];
}
}
—————————————————— Data Arrangement ————————————————————
for (i=0;i<n-1;i++)
for (j=i+1;j<n;j++)
if (Sum[j]>sum[i])
{
T=sum[i];
SUM[I]=SUM[J];
sum[j]=t;
strcpy (Name_t,name[i]);
strcpy (Name[i],name[j]);
strcpy (name[j],name_t);
}
printf ("\n\n************************ score ****************************\n\n");
printf ("%-12s%-15s%-15s%-15s\n", "Rank", "name", "Total score", "average score");
for (i=0;i<n;i++)
{
printf ("%-12d%-15s%-15d%-15.2f\n", i+1,name[i],sum[i],sum[i]/3.0);
}
printf ("\n\n************************************************************\n\n");
return 0;
}
2016.05.31 Tuesday C + + two-dimensional arrays