易读文库
{int i, j, p ;struct student t; /* 工作变量 */
/* 输入1000个学生的记录,包括学号、姓名和三门课成绩,并计算个人的平均分 */ printf(“\\nInput the student’s number,name and scores:”); for(i = 0; i < 1000; i++) { printf(“No %d \\n”,i+1); /* 提示输入第i个同学的信息 */
scanf(“%d,%s,%d,%d,%d”, &stud[i].num, stud[i].name, &stud[i].score[0],&stud[i].score[1],&stud[i].score[2]); stud[ i ].avr = (stud[i].score[ 0 ]+ stud[i].score[ 1 ]+ stud[i].score[ 2 ]) /3.0 ; }
/*使用选择法排序,按照平均分从低到高排序 */ for(i = 0; i < 999; ++i) { p = i;
for(j = i + 1; j < 1000; j++ )
if(stud[j].avr < stud[p].avr ) p = j;
t=stud[p]; stud[p]=stud[i];stud[i]=t;}
/* 输出 */
printf(“The student score:\\n”); for(i = 999; i >= 0; i--)
printf(“%d %s %f\\n”, stud[i].num, stud[i].name, stud[i].avr); } 2. #include \ #include \ void main()
{ FILE *fp; char ch;
int line=1;
if((fp=fopen(“d:/a.txt”,”r ”))==NULL){ printf(\ exit(0); }
while(!feof(fp)){
ch=fgetc(fp);
if(ch>='A'&&ch<='Z') ch+=32; putchar(ch);
if(ch=='\\n') line++; } fclose(fp);
printf(\总行数 %d\\n\
读出字符和大写转小写处理

