C语言程序设计项目教程课后参考答案.docx
C语言程序设计工程教程课后参考答案连雁平武夷学院数学与计算机学院第一章:1 .填空题(2) /*/(6) .c.obj(5) D (6) A(1)函数 主函数 函数(3)连接 (4) #(5).h.选择题(1) C (2) C (3) D (4) B.程序设计题(1) #include <stdio.h>void main()(printf("*");printf("*”);printf("*");)(2) #include <stdio.h>void main()printf(" *») printf(“这是我的C程序”); printf("* * *')第二章:L填空题(1) Ox (2) 0(3) 5(4) a%2!=0(5) 0(6) x>20&&x<=60(7) 3.500000(8) 0(9) 2(10) 4.选择题(1) C (B答案如果斜杆之间无空格是对的)(2) A (3) B (4) B(5) A (输出结果是字符 5)(6) C(7) B (8) A (9) C (10) A(11) B (12) D (13) D(14) D(15) B (16) A (17) B(18) C C (19) A (20)与第 2 题题目一样 (21) C (22)第一个 w应该是变量x才是,无答案 (23) D (24) D (25) B2 程序设计题(1) #includc <stdio.h>void main()float a=2,b=6,h=3.6;printf(u%f(a+b)*h/2);)(2) #include <stdio.h>void main()int time,h,m,s;scanf(n%dn,&time);s=time%60;m=time/60%60;h=time/3600;printf("时间是d 小时d 分(1 秒”,h,m,s);)第三章:1 .选择题(1) D (2) D (A的答案要修改一下,不然也是不合法)(3)和(4)与第 一题相同(5) D (6) D (7) A (8) B.编程题(1) #include<stdio.h>void main()char c;c=getchar();putchar(c-l);putchar(c);putchar(c+l);)(2) #include<stdio.h>void main()int scoreI,score2,score3,score4,sum;float avr;scanf(H%d,%d,%d,%dn,&scorel,&score2,&score3,&score4);sum=score 1 +score2+score3+score4;avr=sum/4.0;printf("总成绩是:d,平均分是:%fsum,avr);)第四章:L填空题(1) 1(2) 54321(3) (x%3=0|x%7=0) f=l;(4) y is 1.I do this.2 .选择题(1) B (2) D (3) B (4) C (5) A (6) A.编程题(1) #include<stdio.h>void main()int i;scanf("d”,&i);if(i%2=0)printf("d 是偶数!=i);elseprintf("d 是奇数!1);)(2) #include<stdio.h>#include<math.h>void main()(int a,b,i;for(a=3;a<= 100;a+)(b=sqrt(a);for(i=2;i<=b;i+)if(a%i=O)break;if(i>b)printf(n%d ”,a);)(3) #include<stdio.h>void main()(int n,t=l,T=0;for(n= 1 ;n<=5 ;n+)(t*二n;T+=t;)printf(" 1! +2! +3! +4!+5! =%d” ,T);)(4) #include<stdio.h>void main()char ch;int i=0;while(ch=getchar()!=,n,)i+;printf("总共输入d个字符i);)第五章:1 .填空题(1) 14 0(2)常量表达式1常量表达式2(3)按行存放 (4) i*n+j+l(5) 00 (6)首地址 (7)字符 1 (8) string.h (题干中“写入库函数”应该是“包含头文件”) (9) 2 1 (10) for(i=0;i<20;i+)printf("%d;ai);(题 干中应该写明“整形数组a20,下标用i表示”)2 .选择题(1) B (2) D (3) CD (题干“数组a”应该是“数组b”)(4) C (答案C应该是“double c54;")(5) D (B答案中的an应该是am)(6) C (7) D (8) D (9) D (该题与填空题第4题重复)(10) C(11) B (12) C (13) D (14) B (15) B (16) D (17) A (18) B (19) D (20) D (题干“字符中”应该是“字符串")(21) C (22) D (23) D (24) B (25) D3 .分析题(1) 1 0000 (第七行应该是(2) AB LMNP0 1 000(3) SW (case T后面是冒号不是分号)00 100 000 1 0 0000 1(4) array a:(第一个for循环后面的左花括号去掉)(5) 1234566 71318231924 25array b:11121416171 5212262 .编程题(1) #include<stdio.h> void main()(int a20;intprintf(ninput 20 numbers :nn);for (i=0;i<20;i+)scanf(H%dH,&ai);printf(nnn);for(j=0;j<19;j+)for(i=0;i<19-j;i+)if(ai<ai+l)t=ai ;ai=ai+1 ;ai+ l=t; printf(nthe sorted numbers :nH); for(i=0;i<20;i+) printf(n%d n,ai);printf(nnn);)(2) #include <stdio.h>void main()(int a4 4 ,i,j,max,row 1 ,columnl;int min,row2,column2;for (i=0;i<4;i+)for (j=0;j<4;j+)scanf(n%dn,&aij);max=a00 ;row 1 =0;column 1 =0;min=a0 0 ;row2=0;column2=0;for (i=0;i<4;i+)for (j=0;j<4;j+)(if (max<aij)(max=aij;rowl=i;column l=j;)if (min>aij)(min=aij;row2=i;column2=j;)printf(nmax=%d,row=%d,column=%dnH,max,row 1 +1,column 1 + 1);printf(nmin=%d,row=%d,column=%dnn,min,row2+l,column2+l);)(3) #include <stdio.h>void main()(int num44=32,30,49,56,15,7,3192,8,24,17,37,19,98,35;int i,j,datal ,data2,max,min;for (j=0;j<4; j+)(min= numj0;data 1=0;for (i=l; i<4; i+)min=numji;datal = i;)max=numO data 1;data2 = 0;for (i=0; i<4; i+)(if (max<numi data 1 )(max=numi datal ;data2 = i;)if (data2 = j)datal,printf(n 该矩阵的马鞍点是:num%d%d=%dnn, data2, numdata2 data 1 );)(4) #include<stdio.h>#include<string.h>void main()(char str50;int i,s;printf(”请输入一行字符串:)gets(str);s=strlen(str);printf("字符串倒序输出:”);for(i=s-l;i>=0;i)printf(n%c,stri);(5) #include<stdio.h>#include<string.h>void main()(char a80,strl80,str280,str380;printf(”请输入三个字符串)printf。字符串 strl: ”);gets(strl);printf。'字符串 str2: ");gets(str2);printf("字符串 str3: n);gets(str3);if(strcmp(strl,str2)>0)strcpy(a,strl);else strcpy(a,str2);if(strcmp(a,str3)>0) puts(a);else puts(str3);)(6) #include<stdio.h>void main()int score203,sum20,ij,t;for(i=0;i<20;i+)for(j=0;j<3;j+)scanf(n%dn,&scoreij);for(i=0;i<20;i+)sumi=O;for(i=0;i<20;i+)for(j=0;j<3;j+)sum i+=score i j ;for(i=0;i<20;i+)for(j=0;j<20-i;j+)if(sumj<sumj+1)t=sum(j;sumj=sumj+l;sumj+l=t;printf(”总成绩从大到小顺序是:H);for(i=0;i<20;i+)printf(n%4d,sumi);第六章L填空题2624(1) int (2)值传递 址传递 (3)2 (4) static (5) 1(6) 10,20,40,40(7)(8) 13.选择题(1) B (2) A (3) D (4) C (5) A (6) B (7) D (8) B程序设计题1. int fun(int x,int y)char c;switch(c=getchar()case '+':return x+y;break;case *':return x*y;break;default:printf("输入的符号不对! ”); )2. #include<string.h>void strfun(char a,char b)(int alen=strlen(a);int blen=strlen(b);int i;for(i=0;i<blen;i+) aalen+i=bi;puts(a);)3. float fun(int n)(float i,t=l.O,s=O;for(i=l;i<=n;i+)(t=t/i;s+=t;)return s;)4. void charsum(char s80|,int sum|4)(int i,strl;strl=strlen(s);for(i=0;i<strl;i+)if(si>='a&&sik='z')|(si>='A&&sik=Z)sum0+;else if(si>='l'&&si<=,9,) suml+;else if(si=f') sum +;elsesum3+;printf("字母个数是:d,数字个数是:d,空格个数是:d,其他字符个数 是:dn”,sumO,sum 1 ,sum,sum3);)5. #include <stdio.h>#define MAX(a,b,c) (a)>(b)?(a):(b)>(c)?(a)>(b)?(a):(b):(c) void main() int a,b,c;printf(”请输入三个数字:”); scanf(n%d%d%dn,&a,&b,&c);printf("最大的数字是:%dMAX(a,b,c);)