A small example of a C-language array pointer

Source: Internet
Author: User

1, Function: Enter 6 Student's 5 course result, calculate each student's average score and each course's average score.
2, C language Implementation code: (In fact, is the use of two-dimensional arrays to implement, the two-dimensional array of reference transfer using the array pointer to complete)

Copy Code code 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.
*/
int main () {
Float Socore T];
Input_array (a);
Avg_course (a);
Avg_score (a);
}
Void Input_array (float (*score) [STUDENT]) {
int i, J;
for (i=0; i<score; i++) {
printf ("Input"% 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=%fn", 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.