/* Program Author: Guan Ning
Site: www.cndev-lab.com
All manuscripts are copyrighted. If you want to reprint them, be sure to use the famous source and author */
# Include <stdio. h>
Main ()
{
Void search_score ();/* define the number of custom Han types as not returned */
Void count_avg ();/* define the number of custom Han types as not returned */
Static float a [3] [4] = {97, 45.5, 66,77}, {88, 92.5, 78.5, 66}, {83, 74.5, 92,100 }}; /* enter the scores of each of the three students for each of the four courses */
Search_score (a, 0);/* change the number of custom courses to display the scores of each course */
Count_avg (* a, 12);/* change the custom number of courses to display the average score of each course for three students */
/* Note that the above * a is actually a [0] Or & a [0] [] 0, and this line is rewritten to count_avg (a [0], 12 ); or count_avg (& a [0] [0], 12) is also true */
}
Void search_score (p, n)
Float (* p) [4];/* defines a pointer Variable p, indicating that it is a pointer to a one-dimensional array containing four Integer Variables */
Int n;/* defines the form parameter n as an integer */
{
Int I;/* defines the variable used for loop I */
For (I = 0; I <4; I ++)/* this loop is used to print the four course scores of one student four times */
{
Printf ("% 7.2f", * (p + n) + I ));
}
Printf ("");
}
Void count_avg (p, n)
Float * p;
Int n;
{
Float * p_end;
Float sum = 0;
Float avg;
P_end = p + n-1;/* calculate the address of the last array element */
For (; p <= p_end; p ++)/* loop to the last element address and stop */
{
Sum + = * p;
}
Avg = sum/n;
Printf ("avg = % 7.2f", avg );
}
/*
Note that this question means to enter the scores of the three same 4 courses, calculate the average value, and display the scores of one of the four courses. In this example, the multi-dimensional array pointer and multi-dimensional array
As a summary of the transfer of the Han number parameter, You can carefully contact and understand what the concept of multi-dimensional array pointer is!
*/