Definition and reference of structural body arrays (III.)

Source: Internet
Author: User
Tags arrays definition printf

Step seventh, define the M a i n () function, listing the complete list of programs.
#include
#include
struct STU
{
Char name[20];
Long number;
float score[4];
} ;
M a i n ()
{
void input (); /* Function declaration */
void Aver ();
void order ();
void output ();
void Out_row ();
struct Stu stud[4]; /* Defines the structure body array */
float row[3];
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[30];
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 (j = 0; J < 4; J + +)
P r i n t F ("% 7"). 2 F | ", a r R [i]. S c o r e [j]);
P r i n t F ("n");
P r i n t F ("----------------------------------------------------------------N " ) ;
}
}
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
void Out_row (Arr,n)
int n;
struct Stu arr[];
{
Float row[4]={0,0,0,0};
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];
R O w [i] = r O w [i]/n;
}
printf ("|%19c|", "");
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");
}

In the program, you should carefully handle the parameters of the array masterpiece function. The first address of an array is passed to the subroutine when the formal parameter and the argument are combined, because the array is the first address of a group. The size of the parameter group is best undefined to indicate consistency with the array that called the function. In the defined structure body, member score[3] is used to represent the average score of the calculation, and also our
The basis for sorting. We cannot compare the array elements to each other, but only the members of the array element score[3]. When you need to exchange, use the whole of the array elements, including names, school numbers, three subjects and the average score to exchange. In the program order () function, the comparison takes: Arr[j].score[3]>arr[j+1].score[3], and the exchange takes:
ARR[J]ARR[J+1]

Contact Us

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.