1、第五届全国ITAT教育工程就业技能大赛复赛试题 C语言程序设计(B卷) 请考生仔细阅读并严格遵守题目中关于文件保存和命名的要求。 请务必按照试卷要求为文件命名。 考生答题完毕后,首先创建以“准考证号”命名的文件夹(形式如:433034683),并将考试结果严格按题目上的命名要求进行命名并直接保存在该文件夹下。 注意:考生不得在该文件夹下创建任何子文件夹,所有考试结果均直接保存在该文件夹根目录下。 然后选中整个文件夹,用Winrar压缩工具打包后存放在本考场指定的考试结果存放地址,经监考老师确认上传无误后方可离开考场。 注意:在提交答案时,请务必选中上
2、述存放作品的文件夹(如前面创建的433034683文件夹,而不是文件夹下的全部文件)进行压缩,在完成答案提交后,请确保上述压缩包仍保存在本地计算机中。 请务必按照试卷要求提交指定的文件,不得包含非题目要求的过程文件和临时文件,不得包含本试题文件和试题素材。 注意:凡违反上述规定的考生,其成绩一律按零分处理。 题目命名要求:请将编写好的源程序以题号命名,例如第1题的源程序保存为“1.C” )。 重要提示:由于时间有限,请考生首先保证编写的程序在Wintc环境下可以编译通过并执行,并在此基础上保证完成考题要求的全部功能,以免因编译不通过影响考生的考试成绩。 1、 编程解决如下
3、问题:鸡翁一,值钱五;鸡母一,值钱三;鸡雏三,值钱一。百钱买百鸡, 问鸡翁,鸡母,鸡雏各几何?(20分) /* HELLO.jc -- Hello, world */ #include "stdio.h" #include "conio.h" main() { int jw,jm,jc; for(jw=1;jw<100;jw++) { for(jm=1;jm<100;jm++) { for(jc=1;jc<100;jc++) { if(jw+jm+jc==100 && 5*jw
4、3*jm+jc/3==100) printf("%d\t%d\t%d\n",jw,jm,jc); } jc=1; } jm=1; } getch(); } 2、 编程实现:有二维数组a[3][3]={{1.3,2.7,3.6},{2,3,4.7},{3,4,1.27}},将数组a的每一行元素均除以该行上绝对值最大的元素,按行输出新数组。(20分) /* HELLO.C -- Hello, world */ #include "stdio.h"
5、 #include "conio.h" #include "math.h" main() { float a[3][3]={{1.3,2.7,3.6},{2,3,4.7},{3,4,1.27}}; int i,j; float max[3]; printf("before:\n"); for(i=0;i<3;i++){ for(j=0;j<3;j++){ printf("%4.2f\t",a[i][j]); } printf("\n"); } for(i=0;i<3;i++
6、){ max[i]=fabs(a[i][0]); for(j=0;j<3;j++){ if(fabs(a[i][j])>max[i]) max[i]=fabs(a[i][j]); } } printf("after:\n"); for(i=0;i<3;i++){ for(j=0;j<3;j++){ printf("%4.2f\t",a[i][j]/max[i]); } printf("\n"); }
7、 getch(); } 3、 编程:设x、y取值为区间[1,10]的整数, f(x,y)=(3x-2y)/(x+y),求使f(x,y)取最小值的x1、y1,要求使用自定义函数实现f(x,y)功能。(20分) /* HELLO.C -- Hello, world */ #include "stdio.h" #include "conio.h" float f(float,float); main() { int x,y,x1,y1; float min; min=f(1,1); for(x=1;x<=10;x++){ fo
8、r(y=1;y<=10;y++){ printf("a[%d][%d]=%4.2f\t",x,y,f((float)x,(float) y )); if(min>f((float)x,(float) y )){ min=f((float)x,(float) y ); x1=x; y1=y; } } } printf("\nx1:%d\ty1:%d\n",x1,y1); getch(); } float f(float a,float b){ float resu
9、lt; result=(3*a-2*b)/(a+b); return result; } 4、 编写函数fun,其功能是:在字符串中所有数字字符前加一个“*”字符,要求通过指针实现。(20分) /* HELLO.C -- Hello, world */ #include"stdio.h" #include"conio.h" char fun( char *s1) {char *s=s1; char a[100]; int i=0; while(*s) if(*s>='0'&&*s<='9') {a[i++]='*';a[i++]=
10、s++;} else a[i++]=*s++; a[i]='\0'; strcpy(s1,a); } main() { char s[80]; printf("enter a string:"); scanf("%s", s); fun(s); printf("the result: %s\n", s); getch(); } 5、 编程:已知学生记录由学号和学习成绩构成,N名学生的记录已存入结构体数组中,找出成绩最低的学生,并输出这个学生的信息,已知学生信息如下。(20分) A01,81;A02,89;A03
11、66;A04,87;A05,77 A06,90;A07,79;A08,61;A09,80;A10,71 /* HELLO.C -- Hello, world */ #include "stdio.h" #include "conio.h" struct student{ char no[100]; float score; }student[]={{"A01",81},{"A02",89},{"A03",66},{"A04",87},{"A05",77}, {"A06",90},{"A07",79},{"A08",61},{"A09",
12、80},{"A10",71} }; main() { float min; int i,a; min=student[0].score; for(i=0;i<10;i++){ if(min>student[i].score){ min=student[i].score; a=i; } } printf("result is %s\t%2.0f",student[a].no,student[a].score); getch(); } 6、 附加题:编写一个函数Inv
13、erseByWord(char *sentence),实现一个英文句子按单词逆序存放的功能,并给出测试程序。(50分) 如:This is an interesting programme. 逆序后变为:.programme interesting an is This /* HELLO.C -- Hello, world */ #include "stdio.h" #include "conio.h" #define ARRSIZE 50 void InverseByWord(char *sentance); void main() { char Ar
14、rSentance[]={"This is an interesting programme"}; InverseByWord(ArrSentance); getch(); } void InverseByWord(char *sentance) { char c1,c2 = ' ',*p = sentance; int index =1 ,i=0 ; char Arr[ARRSIZE]= {'\0'} ; char ArrTmp[ARRSIZE]={' '},*q = ArrTmp; while(*p != '\0') { c1 = *p
15、 if(c1 != ' ') { ArrTmp[index++] = c1 ; } else if(c1==' ') { strcat(ArrTmp,Arr); strcpy(Arr,ArrTmp); index = 1 ; q= ArrTmp ; for(i=0;*q != '\0' ;i++) { *q = '\0' ; q++; } ArrTmp[0] = ' ' ; } p++ ; } strcat(ArrTmp,Arr); strcpy(Arr,ArrTmp); printf("%s\n",Arr); }






