#define MAXSCORE 20
#define QUESTION 10
#define ORDERS 5
main()
{ int p[QUESTION]={0,0,0,0,0,0,0,0,0,0},
n[QUESTION]={0,0,0,0,0,0,0,0,0,0},
s[QUESTION]={0,0,0,0,0,0,0,0,0,0};
int f[ORDERS]={0,0,0,0,0};
int i,score,c,number,pn=0;
char fig,ch[120];
char *title[]={" 90 -- 100 A",
" 80 -- 89 B",
" 70 -- 79 C",
" 60 -- 69 D",
" 0 -- 59 E"}
while(1)
{
printf("Enter number && score1 -- score10 \n");
if (scanf("%d",&number) ==0)
{
gets(ch);
printf("Error! Input again!\n");
continue;
}
for (c=0,i=1;i if (scanf("%d",&p[i])) if (p[i] <= MAXSCORE) _________________________ ; if ( ______________________ ) { gets(ch); printf("Error! Input again!\n"); continue; } for (c=0,score=0,i=0;i if ( _______________ ) { c++; score +=p[i]; n[i]++; s[i] +=p[i]; } fig = (score ==100) ? 'A': (score < 60) ? _____________________; f[ _______ ]++; pn++; printf("Number = %d Score = %d Mark = %c\n",number,score,fig); } printf("STUDENTS = %d\n",pn); for (i=0;i printf("\n Question Students Average\n"); for (i=0;i if (n[i]) printf("%6d%10d%10.2f\n",i+1,n[i], _______________ ); else pritnf ("6d%10d%10s\n",i+1,n[i]," --"); } 本程序?qū)崿F(xiàn)安照每頁寬80列平均分左右兩欄的格式 印出正文文件內(nèi)容. 程序引入數(shù)組buff[] [] [] 和ln [] [], 將從文件 讀出的字符按行存儲于buff[0],行號存于ln[0](對應(yīng)左欄 ), 或buff[1],ln[1](對應(yīng)右欄).約定,文件內(nèi)容先填左欄 填滿后,再填右欄.或左右兩欄填滿,或文件內(nèi)容填完,輸出 一頁的內(nèi)容. 欲輸出的正文文件(小于1000行)的文件名作為主函數(shù) 的參數(shù).主函數(shù)以文件名為參數(shù)調(diào)用函數(shù)dprint()輸出一個 文件.函數(shù)dprint()讀取文件內(nèi)容,控制欄中的一行內(nèi)容的 填寫,當一行填滿時,調(diào)用函數(shù)nextline().函數(shù)nextline() 控制欄中行的變化,左右欄的變化.待左右欄都填滿時,調(diào)用 函數(shù)printout()完成整頁輸出.函數(shù)printout()完成頁面排 版,取ln[0] buff[0]和ln[1] buff[1],將對應(yīng)行號及內(nèi)容 填入line[],逐行輸出. 【程 序】 #include #define LL 80 #define COL 2 #define CSIZE LL/COL-9 #define PL 50 #define MARGIN 3 char buff[COL][PL][CSIZE]; int ln[COL][PL]; int col,row,p; dprint(char *fname) { FILE *fp; int lin,c; if ((fp=fopen(fname,"r"))==NULL) return; lin =0; p=0; col=0; c=getc(fp); while (c!=EOF) { ln[col][row]=++lin; while (c != '\n' && c != EOF) { if (p>= CSIZE) { _________________ ; ln[col][row] = 0; } _________________ = c ; c = getc(fp); } ____________________ ; if (c != EOF) c = getc(fp); } while( col != 0 || row != 0 ) { ln[col][row] = 0; nextline(); } fclose(fp); } nextline() { while(p < CSIZE) buff[col][row][p++] = ' '; if ( _____________ ) { if ( ++col >= COL ) { printout(); _______________; } row = 0; } p = 0; } printout() { int k, i, lpos, col, d; char line[LL]; for(k=0;k for(k=0;k { for(i=0;i for(lpos=0,col=0;col col++) { d = _____________; p = lpos + 4; while (d>0) { line[p--] = _______________; d /= 10; } for(p=lpos+7,i=0;i line[p++] = buff[col][k][i]; } puts(line); } for(k=0;k } main(int argc, char **argv) { int f; for(f=1;f dprint(argc[f]); } 本程序給出兩個函數(shù).函數(shù)create()根據(jù)已知整數(shù)數(shù)組構(gòu)造一個線性鏈表.函 數(shù)sort()采用選擇排序方法對已知鏈表進行排序.為排序方便,函數(shù)sort()于排 序前在鏈表首表元之前生成一個輔助表元.排序完成后,將該輔助表元篩去. 【程 序】 #include #include struct node{ int value; struct node *next; }; struct node *create(int a[], int n) { struct node *h, *q; for(h=NULL;n;n--) { q = (struct node *)malloc(sizeof(struct node)); q->value = ____________; ______________; ______________; } return h; } void sort(struct node **h) { struct node *p,*q,*r,*s,*hl; hl = p = (struct node*)malloc(sizeof(struct node)); p->next = *h; while(p->next != NULL) { q = p->next; r = p; while(p->next != NULL) { if (q->next->value < __________ ) r = q; q = q->next; } if( r != p ) { s = ____________; _____________ = s->next; s->next = ___________; ___________ = s; } p = p->next; } *h = hl->next; free(hl); } int text_data[] = {5,9,3,4,5,7,8}; main() { struct node *h, *p; h = create(test_data, sizeof test_data/size of test_data); for(p=h;p;p=p->next) printf("%5d",p->value); printf("\n"); sort(&h); for(p=h;p;p=p->next) printf("%5d",p->value); printf("\n"); }