# C語言數組指標的小例子

1、功能：輸入6個學生的5門課程成績，計算出每個學生的平均分和每門課程的平均分。
2、C語言實現代碼：（其實就是用二維數組來實現的，二維數組的引用傳遞使用數組指標來完成）

#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(a);
avg_course(a);
avg_score(a);
}
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=%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);
}
}

## Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

## Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

## Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth \$300-1200 USD