您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > C语言程序设计习题解答
《C语言程序设计》习题解答沈国荣隋雪莉闵芳目录第1章C语言程序设计概述..................................................................................................2第2章数据类型及其运算.....................................................................................................3第3章语句与输入输出.........................................................................................................4第4章选择结构程序设计.....................................................................................................6第5章循环结构程序设计.....................................................................................................9第6章数组...........................................................................................................................12第7章函数...........................................................................................................................15第8章编译预处理...............................................................................................................18第9章指针...........................................................................................................................19第10章结构体与共用体.....................................................................................................22第11章位运算.....................................................................................................................26第12章文件操作.................................................................................................................27第1章C语言程序设计概述一、选择题12345678910CBACCBDBDA二、填空题1.函数、main()函数2./*、*/3..C、.OBJ、.EXE4.顺序结构、选择结构、循环结构三、编程题1.【参考代码】#includestdio.hintmain(){printf((学校名称)\n);printf((姓名)\n);return0;}2.【参考代码】#includestdio.hintmain(){printf((学校名称)\n(姓名)\n);return0;}第2章数据类型及其运算一、选择题12345678910CCCABADDC、BB11121314151617181920CADDDCDC注:第5题B选项为:'\'''\017''\t'二、填空题1.字母、数字、下划线2.1、4、4、83.-164.3.55.06.97.68.-609.y%2==110.1、0、1三、程序阅读题1.b2.03.04.10,25.9,10,9,106.3,1,0,07.3,20,30,1第3章语句与输入输出一、选择题12345678910BCCCCBBBDA二、填空题1.123.472.D3.回车4.10,2三、程序阅读题1.2612.203.201,104.y=4630y=46305.*3.140000,3.142*6.c:dec=120,oct=170,hex=78,ASCII=x7.x=1y=2*sum*=310squaredis:1008.24820.220.29.x+y+z=4810.55,,A四、编程题1.【参考代码】#includestdio.hintmain(){charch;printf(请输入一个字符:\n);scanf(%c,&ch);printf(%c的ASCII码为:%d\n,ch,ch);return0;}2.【参考代码】#includestdio.h#definePI3.1416intmain(){doubler,h;doublecl,cs,cv;printf(请输入圆的半径:);scanf(%lf,&r);printf(请输入圆柱高:);scanf(%lf,&h);cl=2*PI*r;cs=PI*r*r;cv=PI*r*r*h;printf(圆的周长为:%.4lf\n,cl);printf(圆的面积为:%.4lf\n,cs);printf(圆柱的体积为:%.4lf\n,cv);return0;}3.【参考代码】#includestdio.hintmain(){intsplitInt,one,ten,hundred;printf(输入要处理的整数:);scanf(%d,&splitInt);hundred=splitInt/100;ten=splitInt%100/10;one=splitInt%10;printf(个位:%d,十位:%d,百位:%d\n,one,ten,hundred);return0;}第4章选择结构程序设计一、选择题123456DCCBBC二、程序阅读题1.102.2,2,23.64.97,b5.c=-16.88887.20,08.2,19.1,12,22,1-2,210.a=1,b=3三、程序完善题1.ab、cx四、编程题1.【参考代码】#includestdio.hintmain(){inta,b,c,d,min;printf(输入4个整数:);scanf(%d%d%d%d,&a,&b,&c,&d);if(ab)min=a;elsemin=b;if(cmin)min=c;if(dmin)min=d;printf(%d\n,min);return0;}2.【参考代码】#includestdio.hintmain(){intnum,a,b,c,d;printf(请输入一个四位整数:);scanf(%d,&num);a=num/1000;b=num%1000/100;c=num%100/10;d=num%10;printf(各位数字之和为:%d\n,a+b+c+d);return0;}3.【参考代码】#includestdio.hintmain(){intx;printf(请输入x:);scanf(%d,&x);printf(y的值为:);if(x0)printf(%d\n,x);elseif(x50)printf(%d\n,3*x-2);elseif(x100)printf(%d\n,4*x+1);elseprintf(%d\n,5*x);return0;}4.【参考代码】#includestdio.hintmain(){intdj;floatzl,je,yfk;printf(请输入等级(1~4):);scanf(%d,&dj);if(dj4||dj1){printf(无此等级的苹果!\n);return0;}printf(请输入重量(公斤):);scanf(%f,&zl);printf(\n);switch(dj){case1:je=5.5*zl;break;case2:je=4.3*zl;break;case3:je=3.0*zl;break;case4:je=2.5*zl;break;}printf(您选择苹果级别:%d级\n,dj);printf(您购买苹果重量:%.2f公斤\n,zl);printf(您应付金额为:%.2f元\n,je);printf(\n);printf(顾客所付金额:);scanf(%f,&yfk);if(yfkje){printf(DataError!\n);return0;}printf(应找您:%.2f元\n,yfk-je);return0;}第5章循环结构程序设计一、选择题12345678(1)8(2)91011CBBBABBBCDCB二、程序阅读题1.1,2,02.m=4,n=23.A2C4E64.1325.46.k=0,m=57.x=88.1.69.998988三、程序完善题1.(ch'Z'&&ch='Z'+4)||(ch'z')ch-262.kk/10continue3.i+t*10s=s+t4.fabs(t)=1e-6f=-f5.i10j%3!=0四、编程题1.【参考代码】#includestdio.hintmain(){intn,i,j,k;printf(Output:\n);for(n=100;n1000;n++){i=n%10;/*个位*/j=(n/10)%10;/*十位*/k=n/100;/*百位*/if(n==i*i*i+j*j*j+k*k*k)printf(%d\n,n);}return0;}2.【参考代码】#includestdio.hintmain(){inti,m,n,t,p,k;printf(Pleaseinput:);scanf(%d,%d,&m,&n);if(mn){t=n;n=m;m=t;}p=m*n;while(n!=0)/*余数不为0,继续相除,直到余数为0*/{i=m%n;m=n;n=i;}k=p/m;printf(%d,%d\n,m,k);return0;}3.【参考代码】#includestdio.hintmain(){inti,n,t,sum;t=1;sum=0;printf(Pleaseinput:n=);scanf(%d,&n);for(i=1;i=n;i++){t=t*i;sum=sum+t;}printf(1!+2!+…+%d!=%d\n,n,sum);return0;}4.【参考代码】#includestdio.hintmain(){inti,m;doublesum=0,k=1;printf(Pleaseinput:m=);scanf(%d,&m);for(i=1;i=m;i++){sum=sum+k/i;k=-k;}printf(sum=%4.2f\n,sum);return0;}第6章数组一、选择题12345678910111213141516DDDBCCBCCDDBDDCD二、程序阅读题182430,24125t*M6mo7fwo三、程序完善题1k=ij=ia[k]=maxa[j]=max2sum+=score[i]score[i]avg3s[i]=s[i]+a[i][j]printf(\n);4j=strlen(str)–1str[j]=k5(c=getchar())!='#'num[c-'A']+=1四
本文标题:C语言程序设计习题解答
链接地址:https://www.777doc.com/doc-2344630 .html