C語言數(shù)組指針的小例子
來源:易賢網(wǎng) 閱讀:863 次 日期:2014-09-05 14:55:00
溫馨提示:易賢網(wǎng)小編為您整理了“C語言數(shù)組指針的小例子”,方便廣大網(wǎng)友查閱!

1、功能:輸入6個學生的5門課程成績,計算出每個學生的平均分和每門課程的平均分。

2、C語言實現(xiàn)代碼:(其實就是用二維數(shù)組來實現(xiàn)的,二維數(shù)組的引用傳遞使用數(shù)組指針來完成)

復制代碼 代碼如下:

#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);

}

}

更多信息請查看IT技術(shù)專欄

更多信息請查看網(wǎng)絡編程
易賢網(wǎng)手機網(wǎng)站地址:C語言數(shù)組指針的小例子

2025國考·省考課程試聽報名

  • 報班類型
  • 姓名
  • 手機號
  • 驗證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)