?? al6_4.c
字號:
/*案例代碼文件名:AL6_4.C*/
/*功能:計算個人平均成績與各科平均成績,并在屏幕上顯示出來。*/
#define NUM_std 5 /*定義符號常量人數為5*/
#define NUM_course 4 /*定義符號常量課程為4*/
#include "stdio.h"
main()
{int i,j;
static float score[NUM_std+1][NUM_course+1]={{78,85,83,65}, {88,91,89,93}, {72,65,54,75},
{86,88,75,60}, {69,60,50,72}};
/*以上定義一個(NUM_std+1)*(NUM_course+1)的2維數組,并初始化,留下最后一列score[i][NUM_course]存放個人平均成績,最后一行score[NUM_std][i]存放學科平均成績*/
for(i=0;i<NUM_std;i++)
{for(j=0;j<NUM_course;j++)
{score[i][NUM_course] += score[i][j]; /*求第i個人的總成績*/
score[NUM_std][j] += score[i][j]; /*求第j門課的總成績*/
}
score[i][NUM_course] /= NUM_course; /*求第i個人的平均成績*/
}
for(j=0;j<NUM_course;j++)
score[NUM_std][j] /= NUM_std; /*求第j門課的平均成績*/
clrscr();
/*輸出表頭*/
printf("學生編號 課程1 課程2 課程3 課程4 個人平均\n");
/*輸出每個學生的各科成績和平均成績*/
for(i=0;i<NUM_std;i++)
{printf("學生%d\t",i+1);
for(j=0;j<NUM_course+1;j++)
printf("%6.1f\t",score[i][j]);
printf("\n");
}
/*輸出1條短劃線*/
for(j=0;j<8*(NUM_course+2);j++)
printf("-");
printf("\n課程平均");
/*輸出每門課程的平均成績*/
for(j=0;j<NUM_course;j++)
printf("%6.1f\t",score[NUM_std][j]);
printf("\n");
getch();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -