Small Example of C language array pointer

Source: Internet
Author: User

1. function: enter 5 course scores of 6 students and calculate the average score of each student and the average score of each course.
2. C language implementation code: (in fact, it is implemented using two-dimensional arrays. the reference and transfer of two-dimensional arrays are completed using array pointers) Copy codeThe Code is as follows: # include <stdio. h>
# Define STUDENT 5
# Define SCORE 6
Void input_array (float (* score) [STUDENT]);
Void avg_score (float (* score) [STUDENT]);
Void avg_course (float (* score) [STUDENT]);
/**
* Calculate student average score and course average socore.
*/
Int main (){
Float a [SCORE] [STUDENT];
Input_array ();
Avg_course ();
Avg_score ();
}
Void input_array (float (* score) [STUDENT]) {
Int I, j;
For (I = 0; I <SCORE; I ++ ){
Printf ("input the % d student score:", I + 1 );
For (j = 0; j <STUDENT; j ++ ){
Scanf ("% f", score [I] + j );
}
}
}
Void avg_course (float (* score) [STUDENT]) {
Int I, j;
Float s;
For (j = 0; j <STUDENT; j ++ ){
Printf ("course % d", j );
}
Printf ("\ n ");
For (I = 0; I <SCORE; I ++ ){
S = 0;
For (j = 0; j <STUDENT; j ++ ){
Printf ("% f", * (score [I] + j ));
S + = * (score [I] + j );
}
Printf ("\ ts = % f, avg = % f \ n", s, s/STUDENT );
}
}
Void avg_score (float (* score) [STUDENT]) {
Int I, j;
Float s;
For (I = 0; I <STUDENT; I ++ ){
S = 0;
For (j = 0; j <SCORE; j ++ ){
S + = * (score [j] + I );
}
Printf ("% f", s/SCORE );
}
}

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.