一、选择题
1. 在每个C语言程序中都必须包含有这样一个函数,该函数的函数名为(A)。
A.main B.MAIN C.name D.funtion
2.C语言原程序文件的缺省扩展名为(A)。
A.cpp B.exe C.obj D.C
3.由C语言目标文件连接而成的可执行的缺省扩展名为(B)。
A.cpp B.exe C.obj D.C
4.程序运行中需要从键盘输入多于一个数据时,各数据之间应使用(D)符号作为分隔符。A.空格或逗号 B.逗号或回车 C.回车或分号 D.空格或回车
5.每个C语言程序的编译错误分为(B)类。
A.1 B.2 C.3 D.4
6.设x和y均为逻辑值,则x && y为真的条件是(A)。
A.它们均为真 B.其中一个为真 C.它们均为假 D.其中一个为假
7.设有语句“int a=12;a+=a*a;”,则执行结束后,a的值为(C)。
A.12 B.144 C.156 D.288
8.x>0 && x<=10的相反表达式为(A)。
A.x<=0 || X>10 B.x<=0 && x>10 C.x<=0 || x<=10 D.x>0 && x>10 9.字符串“a+b=12\n”的长度为(B)。
A.6 B.7 C.8 D.9
10.在下列符号常量定义中。错误的定义语句格式为(C)。
A.const M1=10; B.const int M2=20; C.const M3 10 D.const char mark=’3’; 11.带有随机函数的表达式rand()%20的值在(C)区间内,
A.1~19 B.1~20 C.0~19 D.0~20
12.当处理特定问题时的循环次数已知时,通常采用(A)循环来解决。
A.for B.while C.do-while D.switch
13.在switch语句的每个case块中,假定都是以break语句结束的,则此switch语句容易被改写为(B)语句。
A.for B.if C.do D.while
14.for语句能够被改写为(D)语句。
A.复合 B.if C.switch D.while
15.下面循环语句执行结束后输出的i值为(B)。
for(int i=0;i A.n/2 B.n/2+1 C.n/2-1 D.n-1 16.在下面循环w语句中内层循环体S语句的执行次数为(D)。 for(int i=0;i for(int j=i;j A.n2 B.(n+1)/2 C.n(n-1)/2 D.n(n+1)/2 17.在下面的do循环语句中,其循环体被执行的次数为(A )。 int i=0;do i++;while(i*i<10); A.4 B.3 C.5 D.2 1. 在下面的一维数组定义中,(C)语句有语法错误。 A.int a[]={1,2,3}; B.int a[10]={0}; C.int a[]; D.int a[5];n 2.在下面的二维数组定义中,(C)语句是正确的。 A.int a[5][]; B.int a[][5]; C.int a[][3]={{1,3,5},{2}}; D.int a[](10) 3.假定一个二维数组的定义语句为“int a[3][4]={{3,4},{2,8,6}};”,则元素a[1][2]的值为(C)。 A.2 B.4 C.6 D.8 4.假定一个二维数组的定义语句为“int a[3][4]={{3,4},{2,8,6}};”,则元素a[2][1]的值为(A)。 A.0 B.4 C.8 D.6 5.将两个字符串连接起来组成一个字符串时,选用(C)函数。 A.strlen() B.strcap() C.strcat() D.strcmp() 1. 在下面的(C)函数声明语句存在语法错误。 A.AA(int a,int b); B.AA(int ,int) C.AA(int a;int b) D.AA(int a,int) 2.在下面的(C)不能作为函数的返回类型。 A.void B.int C.new D.long 3.下面正确的函数原型语句是(B)。 A.int Function(void a); B.void Function(int); C.int Function(a); D.void int(double a); 4.函数调用func(exp1,exp2),exp3*exp4-exp5)中所含实参的个数为(B)个。 A.1 B.2 C.4 D.5 5.下面的标识符中,(C)是文件级作用域。 A.函数形参 B.语句标号 C.外部静态类标识符 D.自动类标识符 6.下面的标识符中,(B)具有全局级作用域。 A.函数形参 B.全局变量 C.内部静态类标识符 D.自动变量符 7.假定p是一个指向float型数据的指针,则p+1所指数据的地址比p所指数据的地址大( C)字节。 A.1 B.2 C.4 D.8 8.假定a为一个字符数组名,则a[8]的地址比该数组的首地址大( B )个字节。 A.4 B.8 C.16 D.32 9.假定a为一个数组名,则下面的( B )表示有错误。 A.a[i] B.*a++ C.*a D.*(a+1) 10.用calloc函数创建具有10个整型元素的一维数组的正确语句是( C )。 A.int *p=calloc(10,2); B.int *p=callo(10; C.int *p=calloc(10,4); D.int *p=malloc(10); 11.假定变量m定义为“int m=7;”,则定义p的正确语句为( B )。 A.int p=&m; B.int *p=&m; C.int &p=*m; D.int *p=m; 12.假定k是一个double类型的变量,则定义指向k的[电脑商场特别版1] 变量p的正确语句为( B )。 A.double p=&k; B.double *p=&k; C.double &p=*k; D.char *p=”Thank you!”; 13.假定一条定义语句为“int a[10],x,*pa=a;”,若要把数组a中下标为3的元素赋值给x,则不正确的语句为( D )。 A.x=pa[3]; B.x=*(a+3); C.a=a[3]; D.x=*pa+3; 14.假定有定义“int b[10];int *pb;”,则不正确的赋值语句为( C )。 A.pb=b; B.pb=&b[0]; C.pb=b+2; D.pb=b[5]; 15.假定指针变量p定义为“int *p=new int(100);”,要释放p所指向的动态内存,应使用语句( D )。 A.delete[p]; B.delete *p; C.delete &p; D.delete []p; 16.假定指针变量p定义为“int *p=calloc(30,sizeof(int));”,要释放p所指向的动态内存,应使用语句( D )。 A.delete[p]; B.deldete(p); C.free[]p; D.free(p); 1. 假定有“struct BOOK{char title[40];float price;};struct BOOK *book;”,则不正确的语句为(A)。 A.struct BOOK *x=malloc(book); B.struct BOOK x={“C++ Programming”,27.0}; C.struct BOOK *x=malloc(sizeof(BOOK)); D.struct BOOK **x=&book; 2. 假定有“struct BOOK{char title[40];float price;} book;”,则正确的语句为(B)。 A.struct BOOK x=&book; B.struct BOOK *x=&book; C.struct BOOK x=calloc(BOOK); D.struct BOOK *x=BOOK; 3.表示文件结束的符号常量为(C)。 A.eof B.Eof C.EOF D.feof 4.C语言中系统函数fopen()是(D)一个数据文件的函数。 A.读取B.写入C.关闭D.打开 5.从一个数据文件中读入以换行符结束的一行字符串的函数为(B)。 A.gets() B.fgets() C.getc() D.fgetc() 6.向一个二进制文件写入信息的函数fwrite()带有(D)参数。 A.1 B.2 C.3 D.4 二、填空题 1.C语言中的每条简单语句以___;_______作为结束符。 2.C语言中的每条复合语句以___}_______作为结束符。 3.在C语言程序的每个程序行后面或单独一行的开始使用注释的标记符为___//___。4.单行或多行注释的结束标记符为__*/_____。 5.在一个C程序文件中,若要包含另外一个头文件或程序文件,则应使用以__#include___标识符开始的预处理命令。 6.在#include命令中所包含的头文件,可以是系统定义的头文件,也可以是__用户___定义的头文件。 7.一个函数定义由__函数头______和函数体两部分组成。 8.用于输出表达式的标准输出函数是_printf( )_________。 9.当不需要函数返回任何值时,则应使用__void_______标识符定义函数类型。 10.执行“printf(“%d-%d=%d”,43,18,43-18);”语句后得到的输出结果为__43-18=25_______。 11.每个C程序文件在编译时可能出现有警告性错误,其对应的标识符为__warning______。12.每个C程序文件在编译时可能出现有致命性错误,其对应的标识符为__error______。13.十进制数25表示成符合C语言规则的十六进制数为___0x19___。 14.在C语言中,转义字符序列___\n___表示一个换行符。 15.执行“printf(“%c”,’F’-2);”语句后得到的输出结果为__D___。 16.已知’A’~’Z’的ASCII码为65-90,当执行“int x=’C’+5;”语句所x的值为___72___. 17.假定一个枚举类型的定义为“enum RB{ab,ac=3,ad,ae}x=ad;”,则x的值为___4___. 18.char类型的大小为__1__个字节。 19.int类型的大小为__4__个字节。 20.float类型的大小为__4__个字节。 21.十进制数28类型为___int___。 22.十进制数3.26类型为___double___。 23.若需要定义一个符号常量,并且使C语言能够进行类型检查,则应在定义语句的开始使用保留字____const___。 24.使用const语句定义一个符号常量时,则必须对它同时进行__定义类型和赋初值__。25.执行“int x=45,y=13;printf(“%d”,x%y);”语句序列后得到的输出结果为___6__。26.假定x=5,则表达式2+x++的值为__7__。 27.表达式(float)25/4的值为___6.25___。 28.表达式(int)14.6%5的值为___4___。 29.表达式x=x+1表示成增量表达式为__x++___。 30.增量表达式++y表示成赋值表达式为___y+=1__。 31.关系表达式(x!=0)的等价表达式为____x___。 32.假定不允许使用逻辑非操作符,则关系表达式x+y>5的相反表达式为___x+y<=5__。33.假定不允许使用逻辑非操作符,则逻辑表达式a>b || b==5的相反表达式为___a<=b && (b>5 || b<5)____。 34.若x=5,y=10,则x>y逻辑值为___false___。 35.若x=5,y=10,则x<=y逻辑值为___true___。 36.假定x=5,则执行“a=(x?10:20);”语句后a的值为__10__。 37.执行“typedef int DataType;”语句后,在使用int定义整型变量的地方都可以使用___DataType___来定义整型变量。 38.在switch语句中,每个语句标号所含保留字case后面的表达式必须是__整型__。39.作为语句标号使用的C保留字case和default只能用于__switch__语句的定义体中。40.在switch语句时,在进行作为条件的表达式求值后,将从某个匹配的标号位置起向下执行,当碰到下一个标号位置时(停止/不停止)___不停止__执行。 41.若do循环的“尾”为“while(++i<10)”,并且i的初值为0,同时在循环体不会修改i的值,由循环体将被重复执行__10___次后正常结束。 42.当在程序执行到___break___语句时,将结束本层循环语句或switch语句的执行。43.在程序中执行到__return__语句时,将结束所在函数的执行过程,返回到调用该函数的位置。 44.在程序执行完__主(main)__函数调用后,将结束整个程序的执行过程,返回到操作系统或C语句集成开发环境界面窗口。 1.假定一维数组的定义为“char * a[8];”,则该数组所含元素的个数为___8_______。2.假定一维数组的定义为“char * a[8];”,则该数组所占存储空间的字节数为___32______。 3.假定二维数组的定义为“int a[3][5]”,则该数组所占存储空间的字节数为___60______。 4.假定二维数组的定义为“char a[M][N];”,则该数组所所含元素的个数为__M*N_____。5.假定二维数组的定义为“double a[M][N];”,则每个数组元素的行下标取值范围在 __0~M-1___之间。 6.假定二维数组的定义为“double a[M][N];”,则每个数组元素的列下标取值范围在__0~N-1___之间。 7.使用“typedef char BB[10][50];”语句定义__BB______为含有10行50列的二维字符数组类型。 8.存储字符’a’需要占用存储器的_1_____个字节空间。 9.空字符串的长度为__0_______。 10.存储一个空字符串需要占用__1___个字节。 11.字符串”a:\\xxk\\数据”的长度为___11______。 12.用于存储一个长度为n的字符串的字符数组的长度至少为__n+1______。 13.strcmp函数用于进行两个字符串之间的___大小比较___。 14.Strcpy函数用于把一个字符串___复制到___另一个字符数组空间中。 15.一个二维字符数组a[10][20]能够存储__ 10___个字符串。 16.一个二维字符数组a[10][20]能够存储的每个字符串的长度至多为___19___. 1.在C语言中,一个函数由函数头和___函数体_______组成。 2.在函数外定义的变量称为全局变量,若没有被初始化则系统隐含对它所赋的初值为___0______。 3.如果一个函数只允许同一程序文件中的函数调用,则应在访函数定义前加上的C保留字为为___static______。 4.如果一个函数直接或间接地调用自身,这样的调用被称为__递归_____调用。 5.调用系统函数时,要先使用#include命令包含该函数的原型语句所在__头___文件。6.函数形参的作用域是该函数的__内部___。 7.假定p所指对象的值为25,p+1所指对象的值为46,则*p++的值为__25______。 8.假定p所指对象的值为25,p+1所指对象的值为46,则*++p的值为__46______。 9.假定p所指对象的值为25,p+1所指对象的值为46,则执行“*(p++);”语句后,p所指对象的值为__46______。 10.假定a是一个指针数组,则a+1所指对象的地址比a地址大__4___字节。 11.若要把一个整型指针p转换为字符指针,则采用的强制转换表达式为___(char*)p______。 12.假定一个数据对象为int*类型,则指向该对象的指针类型为__int**______。 13.假定p是一个指向整数对象的指针,则用___&p___表示指针变量p的地址。 14.若p指向x,则___*p___与x的等价的。 15.NULL是一个符号常量,通常作为空指针值,它值为__ ’\0’ (ASCII码0)___。 1.假定一个结构类型的定义为“struct A{int a,b;A*c;};”,则该类型的大小为___12_______字节。 2.假定一个结构类型的定义为“struct B{int a[5],char *b;};”,则该类型的大小为___24_______字节。 3.假定一个结构类型的定义为“struct D{int a;union{int b;double c;};struct D* d[2];};”,则该类型的大小为___20 _______字节。 4.假定要动态分配一个类型为struct Worker的具有n个元素的数组,并由r指向这个动态数组,则使用语句的表达式为struct Worker* r=__(Worker*)malloc(n*sizeof(Worker));_____。5.假定要访问一个结构x中的由a指针成员所指向的对象,则表示方法为__x.(*a)___。6.假定要访问一个结构指针p所指向对象中的b指针成员所指的对象,则表示方法为_____ *(p->b)___ 7.与结构成员访问表达式(*fp).score等价的表达式是__fp->score______。 三、写出下列每个程序运行后的输出结果 1. #include void main() { int x=5;switch(2*x-3){ case 4:printf("%d ",x); case 7:printf("%d ",2*x+1); case 10:printf("%d ",3*x-1);break; default:printf("%s ","default\n"); } printf("%s\n","switch end."); } 输出结果为: 11 14 switch end. Press any key to continue 2. #include void main() { int i,s=0; for(i=1;i<=6;i++) s+=i*i; printf("s=%d\n",s); } 输出结果为: s=91. Press any key to continue 3. #include void main() { int i,s1=0,s2=0; for(i=0;i<10;i++) if(i%2)s1+=i; else s2+=i; printf("%d %d\n",s1,s2); } 输出结果为: 25 20. Press any key to continue 4. #include void main() { int n=10,y=1; while(n--){y++;y++;} printf("y=%d\n",y); } 输出结果为: y=21. Press any key to continue 5. #include void main() { int f,f1,f2,i; f1=f2=1; printf("%d %d ",f1,f2); for(i=3;i<=10;i++){ f=f1+f2; printf("%d ",f); if(i%5==0)printf("\n"); f1=f2; f2=f; } printf("\n"); } 输出结果为: 1 1 2 3 5 8 13 21 34 55 Press any key to continue 6. #include #include void main() { int i,n; for(n=2;n<=20;n++){ int temp=(int)sqrt(n);//sqrt(n)求出n的平方根并取整 for(i=2;i<=temp;i++) if(n%i==0)break; if(i>temp)printf("%d ",n); } printf("\n"); } 输出结果为: 2 3 5 7 11 13 17 19 Press any key to continue 7. #include #include const int M=20; void main() { int i,c2,c3,c5; c2=c3=c5=0; for(i=1;i<=M;i++){ if(i%2==0)c2++; if(i%3==0)c3++; if(i%5==0)c5++; } printf("%d %d %d\n",c2,c3,c5); } 输出结果为: 10 6 4 Press any key to continue 8. #include #include const int M=20; void main() { int i,s; for(i=1,s=0;i<15;i++){ if(i%2==0 || i%3==0)continue; printf("%d ",i); s+=i; } printf("%d\n",s); } 输出结果为: 1 5 7 11 13 37 Press any key to continue 1. #include void main() { int a[10]={12,39,26,41,55,63,72,40,83,95}; int i,i1=0,i2=0; for(i=0;i<10;i++) if(a[i]%2==1)i1++;else i2++; printf("%d %d\n",i1,i2); } 输出结果为: 6 4 Press any key to continue 2. #include #include void main() { int i; char *a[5]={"student","worker","cadre","soldier","peasant"}; char *p1,*p2; p1=p2=a[0]; for(i=0;i<5;i++){ if(strcmp(a[i],p1)>0)p1=a[i]; if(strcmp(a[i],p2)<0)p2=a[i]; } printf("%s %s\n",p1,p2); } 输出结果为: worker cadre Press any key to continue 3. #include int a[10]={4,5,6,15,20,13,12,7,8,9}; void main() { int i,s0,s1,s2; s0=s1=s2=0; for(i=0;i<10;i++){ switch(a[i]%3){ case 0:s0+=a[i];break; case 1:s1+=a[i];break; case 2:s2+=a[i];break; } } printf("%d %d %d\n",s0,s1,s2); } 输出结果为: 42 24 33 Press any key to continue 4. #include void main() { char a[]="abcdbfbgacd"; int i1=0,i2=0,i=0; while(a[i]){ if(a[i]=='a')i1++; if(a[i]=='b')i2++; i++; } printf("%d %d %d\n",i1,i2,i); } 输出结果为: 2 3 11 Press any key to continue 5. #include void main() { int a[3][4]={{1,2,7,8},{5,6,10,6},{9,12,3,4}}; int m=a[0][0]; int ii=0,jj=0; int i,j; for(i=0;i<3;i++) for(j=0;j<4;j++) if(a[i][j]>m){m=a[i][j];ii=i;jj=j;} printf("%d %d %d\n",ii,jj,a[ii][jj]); } 输出结果为: 2 1 12 Press any key to continue 6. #include void main() { int a,b; for(a=1,b=2;b<50;){ printf("%d %d ",a,b); a=a+b; b=a+b; } printf("\n"); } 输出结果为: 1 2 3 5 8 13 21 34 Press any key to continue 三、写出下列每个程序运行后的输出结果 1. #include void SB(char ch){ switch (ch){ case 'A':case 'a': printf("WW");break; case 'B':case 'b': printf("GG");break; case 'C':case 'c': printf("PP");break; default:printf("BB");break; } } void main(){ char a1='b',a2='C',a3='f'; SB(a1);SB(a2); SB(a3);SB('A'); printf("\n"); } 输出结果为: GGPPBBWW Press any key to continue 2. #include #include double SD(int a,int b,char op){ double x; switch(op){ case '+':x=a+b;break; case '-':x=a-b;break; case '*':x=a*b;break; case '/':if(b)x=(double)a/b; else exit(1); break; default:{("运算符错!\n");exit(1);} } return x; } void main(){ int x=20,y=8; printf("%3.2lf ",SD(x,y,'-')); printf("%3.2lf ",SD(x,y,'*')); printf("%3.2lf ",SD(x,y,'/')); } 输出结果为: 12.00 160.00 2.50 Press any key to continue 3. #include void WF(int x,int y){ x=x+y; y=x+y; printf("subs:x,y=%d,%d\n",x,y); } void main(){ int x=18,y=23; printf("main:x,y=%d,%d\n",x,y); WF(x,y); x=2*x; printf("main:x,y=%d,%d\n",x,y); } 输出结果为: main:x,y=18,23 subs:x,y=41,64 main:x,y=36,23 Press any key to continue 4. #include #include void fun(char ss[]); void main(){ char s[15]="567891234"; fun(s); printf("%s\n",s); } void fun(char ss[]){ int i,n=strlen(ss); for(i=0;i char c=ss[i]; ss[i]=ss[n-1-i]; ss[n-1-i]=c; } } 输出结果为: 432198765 Press any key to continue 5. #include void InsertSort(int a[],int n) { int i,j,x; for(i=1;i x=a[i]; for(j=i-1;j>=0;j--)//为x顺序向前寻找合适的插入位置 if(x>a[j])a[j+1]=a[j]; else break; a[j+1]=x; } } void main() { int i; int a[6]={20,15,32,47,36,28}; InsertSort(a,6); for(i=0;i<6;i++)printf("%d ",a[i]); printf("\n"); } 输出结果为: 47 36 32 28 20 15 Press any key to continue 6. #include void main(){ int a[8]={3,5,7,9,11,13,15,17}; int i,*p=a; for(i=0;i<8;i++){; printf("%5d ",*p++); if( (i+1)%4==0 )printf("\n"); } } 输出结果为: 3 5 7 9 11 13 15 17 Press any key to continue 7. #include int LA(int *a,int n){ int i,s=0; for(i=0;i s+=a[i]; return s; } void main(){ int a[]={5,10,15,20,25,30}; int b=LA(a,4); int c=LA(a+2,3); printf("%d %d\n",b,c); } 输出结果为: 50 60 Press any key to continue 8. #include int LB(int *a,int n){ int i,s=1; for(i=0;i return s; } void main(){ int a[]={1,2,3,4,2,4,5,2}; int b=LB(a,4)+LB(&a[3],4); printf("b=%d\n",b); } 输出结果为: b=184 Press any key to continue 1. #include struct Worker{ char name[15]; //姓名 int age; //年龄 float pay; //工资 }; void main(){ struct Worker x={"wanghua",52,23.50}; struct Worker y,*p; y=x;p=&x; printf("%s %d %6.2f\n",https://www.doczj.com/doc/167857738.html,,y.age,y.pay); printf("%s %d %6.2f\n",p->name,p->age,p->pay); } 输出结果为: wanghua 52 23.50 wanghua 52 23.50 Press any key to continue 2. #include #include struct Worker{ char name[15]; //姓名 int age; //年龄 float pay; //工资 }; void main(){ struct Worker x; char *t="louting"; int d=38;float f=493; strcpy(https://www.doczj.com/doc/167857738.html,,t); x.age=d;x.pay=f; x.age++;x.pay*=2; printf("%s %d %6.2f\n",https://www.doczj.com/doc/167857738.html,,x.age,x.pay); } 输出结果为: louting 39 986.00 Press any key to continue 3. #include #include struct Worker{ char name[15]; //姓名 int age; //年龄 float pay; //工资 }; int Less(struct Worker r1,struct Worker r2){ if(r1.age else return 0; } void main(){ struct Worker a[4]={{"abc",25,420},{"def",58,638},{"ghi",49,560},{"jkl",36,375}}; struct Worker x=a[0]; int i; for(i=1;i<4;i++) if(Less(x,a[i]))x=a[i]; printf("%s %d %6.2f\n",https://www.doczj.com/doc/167857738.html,,x.age,x.pay); } 输出结果为: def 58 638.00 Press any key to continue 四、写出下列每个函数的功能 1. #include int SA(int a,int b){ if(a>b)return 1; else if(a==b)return 0; else return -1; } 函数功能为: 根据实参a大于、等于或小于实参b,返回1,0或-1 2. #include int SC(int a,int b,int c){ if(a>=b && a>=c)return a; if(b>=a && b>=c)return b; return c; } 函数功能为: 返回实参a、 b、c中的最大数 3.double SF(double x,int n){ //n为大于等于0的整数 double p=1,s=1; for(i=1;i<=n;i++){ p*=x; s+=p/(i+1); } return s; } 函数功能为: 计算x+x2/2+x3/3+……+xn/(n+1)的值 4. #include int SC(int x){ int a=(int)sqrt(x); int i=2; while(i<=a){ if(x%i==0)break; i++; } if(i<=0)return 0;else return 1; } 函数功能为: 判断一个整数是否是素数 5. #include void trans(int x) { char a[10]; int i=0,rem; do{ rem=x%16; x=x/16; if(rem<10)a[i]=48+rem;//'0'字符的ASCII码为48 else a[i]=65+rem; //'A'字符的ASCII码为55 i++; }while(x!=0); while(i>0)printf("%c",a[--i]); printf("\n"); } 函数功能为: 将一个整数化成十六进制数 1. #include int WB(int a[],int n,int x){ for(int i=0;i if(a[i]==x)return 1; return 0; } 函数功能为: 根据整型数组元素中是否能找到整数x,返回1或0 2. #include int WC(int a[],int n,int k){ int c=0;for(int i=0;i if(a[i]>=k)c++; return c; } 函数功能为: 返回数组中前n个其值大于等于k的元素之和 3. #include #include #include const int N=10; int ff(int x,int y){ int z; printf("%d + %d = ",x,y); scanf("%d",&z); if(x+y==z)return 1;else return 0; } void main() { int i,a,b,c=0; srand(time(0)); //初始化随机数系列 for(i=0;i a=rand()%20+1; //rand90函数产生0-32767之间的一个随机数 b=rand()%20+1; c+=ff(a,b); } printf("得分:%d\n",c*10); } 函数功能为: 函数ff让两个数相加,要求输入其和,判断结果是否正确。在主函数中用随机函数产生两个20以内的随机整数,通过10次调用这个函数,算对一次得10分,计算所得分 4. int fun6(int m,int n,int b=2) { if(m else if(m%b==0 && n%b==0)return b*fun6(m/b,n/b,b); else return fun6(m,n,++b); } 函数功能为: 此函数带有一个默认参数,若使用默认值,则通过递归调用,返回前2参数的最小公倍数;不使用默认值时,若最后一个参数不小于前2个参数,则返回前2参数之乘积; 否则,通过递归调用,返回前2参数最小公倍数的n倍数。 5. #include #include void LI(int n){ int * a=(int *)[电脑商场特别版2] malloc(n*sizeof(int)); int i; for(i=0;i for(i=n-1;i>=0;i--)printf("%d ",*(a+i)); printf("\n"); free(a); } 函数功能为: 将从键盘输入的n个整数逆序输出 6. #include int LK(double a[],int n){ double s=0;int i,m=0; for(i=0;i s/=n; for(i=0;i return m; } 函数功能为: 求不小于数组元素之平均值的各元素之和(前n个) 应加入此4字,否则D亦对 必须强制类型转换!否则提示cannot convert from 'void *' to 'int *' 五、根据下列每个题目要求编写程序 1.编写一个函数,函数头格式为“void fun4(char *a , int b[])”,分别求出由字符指针 a所指向的字符串中包含的每种十进制数字出现的次数,把统计结果保存在数组b的相应元素。 #include void fun4(char* a,int b[]){ do{ if(*a>='0' && *a<='9')b[*a-48]++; }while(*a++); } /*void main() { char * a="122333444499888"; int b[10]={0}; fun4(a,b); for(int i=0;i<10;i++) printf("%d ",b[i]); }*/ 2. 编写一个函数,函数头格式为“double Mean(double a[M][N] , int m , int n)”, 要求返回二维数组a[m][n]中所有元素的平均值,假定在计算过程是采用变量v存放平均值。 #include const int M=2,N=3; double Mean(double a[M][N], int m,int n ){ double v=0; for(int i=0;i for(int j=0;j v+=a[i][j]; return v/(m*n); } /*void main() { double a[2][3]={1,2,3,4,5,6}; printf("%lf\n",Mean(a,2,3)); }*/ 3. 编写一个递归函数“int FF(int a[] , int n)”,求出数组a中所有元素n个元 素之积并返回。 #include int FF(int a[] , int n){