# Definition and reference of structural body arrays (II.)

Source: Internet
Author: User
The fourth step, according to the average score ranking, sorting algorithm using bubble method.
void Order (Arr,n)
struct Stu arr[];
int n;
{struct Stu temp;
int i,j,x,y;
F o r (i = 0; i < n-1 i + +)
F o r (j = 0; J < n-1-I; j + +)
if (Arr[j].score>arr[j+1].score)
{temp=arr[j];/knot * The type variable does not allow the whole input or output, but allows reciprocal assignment.
ARR[J]=ARR[J+1]; /* for Exchange */
A r R [j + 1] = t e m p;
}
}
The fifth step, according to the table requirements output.
void output (ARR,N)/* A tabular form of an array of struct types with n elements */
int n;
struct Stu arr[];
{int i,j;
printf ("********************table********************\n") hit, print/watch * head * *
printf ("----------------------------------------------------\ n");
/* Output a horizontal line */
P r i n t f ("| % 1 0 S | % 8 S | % 7 S | % 7 S | % 7 S | % 7 S | \ n "," n A M E "," N u m b e r "," E n g L i s H "," M a t h e M ",
"P H y S i c S", "a v e r a G E");
/* The output effect is: | name| number| english| mathema| physics| average|*/
P r i n t F ("------------------------------------------------------------------------------- n ");
for (i=0;i<n;i++)
{
P r i n t f ("| % 1 0 S | % 8 L D | ", a r R [i]. n A m E, a r R [i]. n u m b e r); /* Output name, school number */
F o r (j = 0; J < 4; J + +)
P r i n t F ("% 7"). 2 F | ", a r R [i]. S c o r e [j]); /* Output of three subjects and the average */
P r i n t F ("n");
P r i n t F ("----------------------------------------------------------------N " ) ;
}
}
The sixth step is to solve the students ' average score and output in the group. In the last row of the output table, the output is averaged into a single section
Performance and overall average.
void Out_row (ARR,N)/* An array of the struct type of n elements for a single average */
int n;
struct Stu arr[];
{
Float row={0,0,0,0};/* Defines a one-dimensional array that holds individual averages */
int i,j;
F o r (i = 0; i < 4; i + +)
{
F o r (j = 0; J < N; j + +)
R O w [i] = r O w [i] + a r R [j]. S c o r e [i]; /* Calculate individual sum */
row[i]=row[i]/n; Count/* Calculate single Average * *
}
printf ("|%19c|", ""); Output by/form * *
for (i=0;i<4;i++)
P r i n t F ("% 7"). 2 F | ", R o w [i]);
P r i n t F ("N--------------------------------------------------n");
}
Step seventh, define the M a i n () function, listing the complete list of programs.
#include
#include
struct STU
{
Char name;
Long number;
float score;
} ;
M a i n ()
{
void input (); /* Function declaration */
void Aver ();
void order ();
void output ();
void Out_row ();
struct Stu stud; /* Defines the structure body array */
float row;
i n p u t (S t u D, 4); /* Call the Custom function */
A V e R (S t u D, 4);
o r d E R (S t u D, 4);
o u T P u t (S t u D, 4);
o u t _ R o W (s t u D, 4);
}
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
void input (Arr,n)
struct Stu arr[];
int n;
{int i,j;
Char temp;
for (i=0;i<n;i++)
{
printf ("\ninput name,number,english,mathema,physic\n");
G e T S (a r R [i]. N a m e);
G e t S (t e M P);
A r R [i]. n u m b e r = a t o L (t e M P);
F o r (i = 0; i < 4; i + +)
{
F o r (j = 0; J < N; j + +)
R O w [i] = r O w [i] + a r R [j]. S c o r e [i]; /* Calculate individual sum */
row[i]=row[i]/n; Count/* Calculate single Average * *
}
printf ("|%19c|", ""); Output by/form * *
for (i=0;i<4;i++)
P r i n t F ("% 7"). 2 F | ", R o w [i]);
P r i n t F ("N--------------------------------------------------n");
}
Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.