Home > Back-end >  This same function
This same function

Time:06-04

//cases of 41: there are n structure variables, with the student's student id, student number, and three grades, output the highest average score student information (including student id, name, 3 course grades and gpa)

# include
# define N 3
Struct student
{
Int num.
Char name [20].
Float score [3].
Float aver.
};
Int main ()
{
Void input (struct student s []);
Struct student Max (struct student s []);/* 15 */
Void print (struct student s);
Struct student s [N], * p=s;
Input (p);
Print (Max (p));
return 0;
}
Void input (struct student s [])
{
int i;
Printf (" please input the student's information: student id, name, three classes: \ n ");
for(i=0; i{
The scanf (" % d % s % f % f % f ", & amp; S [I]. Num, & amp; S [I]. Name, & amp; S [I] score [0], & amp; S [I] score [1], & amp; S [I] score [2]);
S [I] aver=(s [I] score [0] + s [I] score [1] [I] + s score [2])/3;
}
}
Struct student Max (struct student s [])/* 32 */
{
Int I, m=0;
for(i=0; iIf (s [I] aver> S [m]. Aver)
M=I;
Return s [m];
}
Void print (struct student stud)
{
Printf (" \ n scores the highest of the students are: \ n ");
Printf (" student number; % d \ n; % s \ n three classes grades: % 5.1 f, % 5.1 f, % 5.1 f \ n average grade: % 6.2 f \ n ",
Stud. Num, stud. Name, stud. Score [0], stud. Score [1], stud. Score [2], stud. Aver);
}

Function is line 15 and line 32, please? I have noted, bosses analyse, thank you!

CodePudding user response:

Line 15 is a function declaration, if not this line you call this function before 32 rows, it is can't find this function, complains, this line is tells the compiler I have this function, the function just write back,
32 lines to void print (struct student stud) in front of the line is a function prototype function (that is, you say)

CodePudding user response:

reference 1st floor qq_45798109 response:
line 15 is a function declaration, if not this line you call this function before 32 rows, it is can't find this function, complains, this line is tells the compiler I have this function, the function just write back,
32 lines to void print (struct student stud) in front of the line is a function prototype (that is, what you said function)

This is a function of structure defined?

CodePudding user response:

refer to the second floor qq_45815575 response:
Quote: refer to 1st floor qq_45798109 response:
line 15 is a function declaration, if not this line you call this function before 32 rows, it is can't find this function, complains, this line is tells the compiler I have this function, the function just write back,
32 lines to void print (struct student stud) in front of the line is a function prototype (that is, what you said function)

This is a function of structure defined?

Is a return value type is the function of structure type

CodePudding user response:

Here you struct student and student are equivalent, MAX is a parameter for the student one dimensional array, the return value is a function of a student structure

CodePudding user response:

Should return pointer, don't write

CodePudding user response:

The difference between the function declarations and function call: pay attention to the different function parameters, function parameters with the data type of the
Is a function declaration (or function definition, function statements with a semicolon at the end of) , with no type is a function call ~

CodePudding user response:

Into a struct student * Max (... )
Returns the return & amp; S [m];

CodePudding user response:

I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.html
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html
  • Related