![C语言程序设计教程李含光郑关胜清华大学出版社习题答案习题答案[完美打印版].doc_第1页](http://file1.renrendoc.com/fileroot_temp2/2020-3/23/1001bd94-ef53-44a5-a26f-4291e394e5a4/1001bd94-ef53-44a5-a26f-4291e394e5a41.gif)
![C语言程序设计教程李含光郑关胜清华大学出版社习题答案习题答案[完美打印版].doc_第2页](http://file1.renrendoc.com/fileroot_temp2/2020-3/23/1001bd94-ef53-44a5-a26f-4291e394e5a4/1001bd94-ef53-44a5-a26f-4291e394e5a42.gif)
![C语言程序设计教程李含光郑关胜清华大学出版社习题答案习题答案[完美打印版].doc_第3页](http://file1.renrendoc.com/fileroot_temp2/2020-3/23/1001bd94-ef53-44a5-a26f-4291e394e5a4/1001bd94-ef53-44a5-a26f-4291e394e5a43.gif)
![C语言程序设计教程李含光郑关胜清华大学出版社习题答案习题答案[完美打印版].doc_第4页](http://file1.renrendoc.com/fileroot_temp2/2020-3/23/1001bd94-ef53-44a5-a26f-4291e394e5a4/1001bd94-ef53-44a5-a26f-4291e394e5a44.gif)
![C语言程序设计教程李含光郑关胜清华大学出版社习题答案习题答案[完美打印版].doc_第5页](http://file1.renrendoc.com/fileroot_temp2/2020-3/23/1001bd94-ef53-44a5-a26f-4291e394e5a4/1001bd94-ef53-44a5-a26f-4291e394e5a45.gif)
已阅读5页,还剩22页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第1章习题参考答案1单项选择题(1)A (2)C (3)D (4)C (5)B2填空题(1)函数(2)主函数(main)(3)printf() , scanf() 第2章习题参考答案1单项选择题1-5 CBCCC 6-10 CDCDC 11-13 DBB2填空题(1)1 (2)26 (3)6 , 4 , 2 (4)10 , 6(5)3.000000(6)双精度(double)(7)9 (8)字母 ,数字 ,下划线(9)13.700000(10)11(11)(m/10)%10)*100+(m/100)*10+m%10(12)0(13)10 ,9 ,11(15)(x0&y0)|(x0&z0)|(y0|z0)(16)double(17)x=0(18)sqrt(fabs(a-b)/(3*(a+b)(19)sqrt(x*x+y*y)/(a+b)第3章习题参考答案1单项选择题1-5 CCCDD 6-10 BCDBC 11-15 BCBBB 16 A2填空题(1)用;表示结束(2) (3)y=x0?1:x=0?0:-1(4)y%4=0&y%100!=0|y%400=0(5)上面未配对(6)default标号(7)while , do while , for(8)do while(9)本次(10)本层3阅读程序,指出结果(1)yes(2)*&(3)ABother(4)28 70(5)2,0(6)8(7)36(8)1(9)3,1,-1,3,1,-1(10)a=12 ,y=12(11)i=6,k=4(12)1,-24程序填空(1)x:y , u:z(2)m=n , m!=0 ,m=m/10(3)t=0 , sgmin ,5编程题27(1)#include int main() double x,y; scanf(%lf,&x); if(x=1.0&x10) y=2*x-11; else y=3*x-11; printf(%lfn,y); return 0;(2)#include int main() double x,y,z,min; scanf(%lf%lf%lf,&x,&y,&z); if(xy) min=y; else min=x; if(minz) min=z; printf(min=%lfn,min); return 0;(3)#include int main() int y,m,d,flag,s=0,w,i; scanf(%d%d%d,&y,&m,&d); flag=(y%4=0&y%100!=0|y%400=0); w=(y-1)*365+(y-1)/4-(y-1)/100+(y-1)/400)%7; for(i=1;i2) s=s+1; s=(w+s)%7; if(s=0) printf(星期日n); else printf(星期%dn,s); return 0;(4)#include int main() float p,r; scanf(%f,&p); if(p10&p20&p40&p60&p100) r=10*0.1+10*0.075+20*0.05+20*0.03+40*0.015+(p-100)*0.01; printf(%fn,r); return 0;(5)#include int main() char c; while(c=getchar()!=n) if(c=a&c=z) c=c-32; putchar(c); return 0;(6)#includeint main() int m,k=2; printf(输入一个正整数:n); scanf(%d,&m); while(km) if(m%k=0) printf(%4d,k); m=m/k; else k+; printf(%4dn,m); return 0;(7)#includeint main() int a,n,s=0,p=0,i; scanf(%d %d,&n,&a); for(i=1;i=n;i+) p=p*10+a; s=s+p; printf(%dn,s); return 0;(8)#includeint main() int i,j,k; for(i=1;i=9;i+) for(j=0;j=9;j+) for(k=0;k=9;k+) printf(%5d,100*i+10*j+k); return 0;(9)#include#includeint main() float a=-10,b=10,x,f1,f2,f; f1=(2*a-4)*a+3)*a)-6; f2=(2*b-4)*b+3)*b)-6; do x=(a+b)/2; f=(2*x-4)*x+3)*x)-6; if(f*f1=1e-6); printf(%6.2fn,x); return 0;(10)#include#includeint main() int n=2; double eps,t,s=0,x; scanf(%lf %lf,&x,&eps); t=x; s=t; while(fabs(t)=eps) t=-t*(2*n-3)*x*x/(2*n-2); s=s+t/(2*n); n+; printf(%d,%lfn,n,s); return 0;(11)#includeint main() unsigned long s,t=0,p=1; scanf(%u,&s); while(s!=0) if(s%10)%2!=0) t=t+(s%10)*p; p=p*10; s=s/10; printf(%un,t); return 0;第4章习题参考答案1单项选择题1-5 DDDBD 6-10 BADCD 11-14 BDAB2填空题(1)2(2)嵌套 , 递归(3)全局变量 , 局部变量 , 静态变量 , 动态变量(4)auto , static , register , extern(5)外部变量(6)编译 ,运行3阅读程序,指出结果(1)15(2)5(3)5,4,3(4)i=5 i=2 i=2 i=4 i=2(5)求水仙花数(6)-5*5*5(7)30(8)0 10 1 11 2 124程序填空(1)float fun(float , float) , x+y,x-y , z+y,z-y(2)x , x*x+1(3)s=0 , a=a+b5编程题(1)#includeunsigned int fun(unsigned int);int main() unsigned int s; scanf(%u,&s); printf(%un,fun(s); return 0;unsigned int fun(unsigned int s) unsigned int p=0; while(s!=0) p=p+s%10; s=s/10; return p;(2)#include#include#includevoid f1(float,float,float,float);void f2(float,float,float,float);void f3(float,float,float,float);int main() float a,b,c,d; scanf(%f %f %f,&a,&b,&c); if(a=0) printf(不是一元二次方程n); exit(0); d=b*b-4*a*c; if(d0) f1(a,b,c,d); else if(d=0) f2(a,b,c,d); else f3(a,b,c,d); return 0;void f1(float a,float b,float c,float d) float x1,x2; x1=(-b+sqrt(d)/(2*a); x2=(-b-sqrt(d)/(2*a); printf(%.2f ,%.2fn,x1,x2); void f2(float a,float b,float c,float d) float x1,x2; x1=-b/(2*a); x2=-b/(2*a); printf(%.2f ,%.2fn,x1,x2); void f3(float a,float b,float c,float d) float x1,x2; x1=-b/(2*a); x2=sqrt(-d)/(2*a); printf(%.2f+i*%.2fn,x1,x2); printf(%.2f-i*%.2fn,x1,x2); (3).#includedouble p(int,double);int main() int n; double x; do scanf(%d,&n); while(n0); scanf(%lf,&x); printf(%lfn,p(n,x); return 0;double p(int n,double x) double pn; if(n=0) pn=1; else if(n=1) pn=x; else pn=(2*n-1)*x*p(n-1,x)-(n-1)*p(n-2,x)/n; return pn;(4)#include#define RATE 0.053double fun(float);void display(float,int);int main() float dep; int season; scanf(%f %d,&dep,&season); display(dep,season); return 0;double fun(float d) return d*RATE;void display(float d,int s) int i; printf(季度 利 余额n); printf(-n); for(i=1;i=s;i+) printf(%-4d %-.2f %-.2fn,i,fun(d),fun(d)*i+d); printf(-n); (5)#includedouble fun(void);int main() printf(%lfn,fun(); return 0;double fun(void) double s=0; int n=1; while(double)(2*n-1)/(2*n)*(2*n)1e-4) s=s+(double)(2*n-1)/(2*n)*(2*n); n+; return s;(6)#includeint fun(int);int main() int w; scanf(%d,&w); printf(%dn,fun(w); return 0;int fun(int w) int n=1,p=1,m; m=w; while(m10) m=m/10; p=p*10; n+; return w%p;第5章习题参考答案1、选择题:1-5 C (B C) BBA 6-8 DDB2、填空题(1) 0,9(2) float realArray100,char strArray16,int intArray1000(3) 运算符 sizeof(4) 6字节3、阅读程序,写出下面程序的运行结果(1) aa bb cc dd(2) ab c d(3)ahAMa(4)0010(5) 1 3 4 5(6)This is the title. Name 1 is Rosalinda Name 2 is Zeke The biggest name alpabetically is Zeke Both names are Rosalinda Zeke(7)0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 0 2 5 6 8 10 748 14 0 3 6 9 12 15 18 21 0 4 8 12 16 20 24 28 0 5 10 15 20 177 30 35 0 6 12 18 24 30 36 42 0 7 14 21 28 35 42 494、程序填空(1) aij != aji , 1(2) 0, ai amini , maxi = i , amaxi = amini(3) int a, int b, bi = ai, -999, arraycopy(a,b), bi+(4) asizeof(ch), if5、编程题(1)#includeint main ( ) 1 int a34 = 0, 2,9,7, 5,13,6,8, 27,11,1,3 ; int i,j,temp; for(i=0,j=0;j4;j+) temp = a2-ij; a2-ij = aij; aij = temp; for(i=0;i3;i+) for(j=0;j4;j+) printf(%3d,aij); printf(n); return 0;(2)#includeint main ( ) static int a66; int i,j,t=1; for(i=0;i6;i+) t = i+1; for(j=0;ji+1;j+) aij = t-; for(i=0;i6;i+) for(j=0;j6;j+) printf(%3d,aij); printf(n); return 0;(3)#include #define M 3#define N 4#define R 5int main( ) static int aMN,bNR,cMR; int i,j,k; 2 printf(Matrix a:n); for( i = 0; i M; i+ ) for( j = 0; j N; j+ ) scanf( %d,&aij ); printf(Matrix b:n); for( i = 0; i N; i+ ) for( j = 0; j R; j+ ) scanf( %d,&bij ); for( i = 0; i M; i + ) for( j = 0; j N; j+ ) for( k = 0; k R; k+) cik += aij*bjk; for( i = 0; i M; i+ ) for( j = 0; j R; j+ ) printf( %3d,cij ); printf(n); return 0;(4)#include #define M 5int main( ) static int aM; int i,max = -1,min = 100,maxi,mini,temp; for( i = 0; i M; i+ ) scanf( %d,&ai ); /099间的值 for( i = 0; i M; i+ ) if( max ai ) min = ai; mini = i; temp = amaxi; amaxi = amini; amini = temp; for( i = 0; i M; i+ ) printf( %3d,ai ); return 0; 3(5)#include #define M 3#define N 4int main( ) static int aMN; int max = -1,sumcol=0,sumrow=0; int i,j,maxi,col; for( i = 0; i M; i+ ) sumrow = 0; for( j = 0; j N; j+ ) scanf( %d,&aij ); sumrow += aij; if ( max 0); scanf(%d,&col); for( i = 0; i M; i + ) sumcol += aicol-1; printf(The %dth rows sum is max, max=%dn,maxi+1,max); printf(The %dth columns sum=%dn,col,sumcol); return 0;(6)#include #define M 81int main( ) static char strM; int i,count = 0; char ch; gets(str); fflush(stdin); /清空输入缓冲区,以便读入字符数据 printf(Which character will be found?); ch = getchar(); for( i = 0; i strlen(str); i+ ) if( ch = stri ) count+; printf( The number of character %c is %dn,ch,count ); 4 return 0;(7)#include #include #define N 10 /同学人数#define M 5 /课程数void enter_scores(void);void sort_scores(int scoreM, int averageN3);void disp_scores(int scoreM);void histogram(int n, int scoreM);void printchar(int n);static int scoreNM;static int averN3; /第1列为均值,第2列原始顺序,第3列为均值逆序int main() int course; enter_scores(); printf(n=Oringenal Score Start=n); disp_scores(score); printf(n=Oringenal Score End=n); printf(n=Sorted Score Start=n); sort_scores(score,aver); printf(n=Sorted Score End=n); printf(nWhich class will be statisticed?n); scanf(%d,&course); histogram(course, score); system(Pause); return 0;/* 输入成绩 */void enter_scores() int i, j; for(i=0; iN; i+) for(j=0; jM; j+) scanf(%d,&scoreij); averi0 += scoreij; for( i = 0; i N; i+ ) for ( j = 1; j 3; j+ ) 5 averij = i;/* 成绩排序. */void sort_scores(int scoreM, int averageN3) int i,j,t; int temp,tempindex; for( i = 0; i N - 1; i+ ) for( j = 0; j N - 1 - i; j+ ) if ( averagej0 averagej+10 ) temp = averagej0; averagej0 = averagej+10; averagej+10 = temp; tempindex = averagej2; averagej2 = averagej+12; averagej+12 = tempindex; printf(n Score1 Score2 Score3 Score4 Score5n); for( i = 0; i N; i+ ) t = averagei2; for( j = 0;j M; j+ ) printf(%8d, scoretj); printf(n); /* 输出成绩 */void disp_scores(int scoreM) int i, j; printf(n Score1 Score2 Score3 Score4 Score5n); for( i = 0; i N; i+ ) for( j = 0;j M; j+ ) printf(%8d, scoreij); printf(n); void printchar(int n) 6 int i; for (i = 0; i n; +i) putchar(*);void histogram(int course, int scoreM) int i,temp; int segs5 = 0; int scN; for( i = 0; i N; i+ ) sci = scoreicourse; for (i = 0; i N; i+)/* 统计各分段人数 */ temp = (int)sci/10; segs temp6?0:temp-5+; /* 成绩/10,将成绩分段 */ printf(nSegment Numbern); for (i = 0; i 5; i+) /* 输出直方图,每段的人数 */ printf(%3d: %5d| , (i+1)*10+50, segsi); printchar(segsi); putchar(n); putchar(n);(8)#include #define M 81int main( ) static char strM; int i,count = 0; char ch = 0; gets(str); for( i = 0; i strlen(str); i+ ) if( ch stri ) ch = stri; for( i = 0; i strlen(str); i+ ) if( ch = stri ) count+; printf( max = %c ,count = %dn,ch,count ); return 0;7第6章习题参考答案1、选择题:1-5 BBDDA 6-10 CCABD 11-15 CBCDA 16 A2、填空题(1) 常量,变量(2) 指针(3)2(4)12,12(5) a0,a33、阅读程序,写出下面程序的运行结果(1)5(2)6(3) abcdefglkjih(4) 976531(5)5,9(6)2,4,5,7,6,0,11,9,7,3,(7)string_a=I am a teacher. string_b=You are a student. string_a=I am a teacher. string_b=I am a teacher.4、程序填空(1) *p != 0, *p-0, j(2) i strlen(str), j=i, k+1(3)a+i, (char)(n%10) + 0(4)*pk = i, a,n,i+1,pk(5) s1+, *s2, s1=p5、编程题(1)#include int main() int a=3,b=7,c=2; int *ptra = &a,*ptrb = &b,*ptrc = &c; int temp; printf(a=%d,b=%d,c=%dn,a,b,c); printf(*ptra=%d,*ptrb=%d,*ptrc=%dn,*ptra,*ptrb,*ptrc); if ( *ptra *ptrb ) temp = *ptra; *ptra = *ptrb; 1 *ptrb = temp; if ( *ptra *ptrc ) temp = *ptra; *ptra = *ptrc; *ptrc = temp; if ( *ptrb *ptrc ) temp = *ptrb; *ptrb = *ptrc; *ptrc = temp; printf(a=%d,b=%d,c=%dn,a,b,c); printf(*ptra=%d,*ptrb=%d,*ptrc=%dn,*ptra,*ptrb,*ptrc); return 0;(2)#include #include void inputdata(int a,int n);void process(int a,int n);void outputdata(int a,int n);int main() int a10,n=10; inputdata(a,n); outputdata(a,n); process(a,n); outputdata(a,n); system(Pause); return 0;void inputdata(int a,int n) /099之间的数 int i; for( i = 0; i n; i+ ) scanf(%d,a+i);void outputdata(int *ptr,int n) int i; 2 printf(n=OutPut Data Start=n); for( i = 0; i n; i+ ) printf(%4d,*ptr+); printf(n=OutPut Data End=n);void process(int *ptr,int n) int i,maxi,mini; int max=-1,min=101; for( i = 0; i n; i+ ) if ( max *(ptr+i) ) min = ptri; mini= i; if ( mini != 0) i = ptr0; ptr0 = ptrmini; ptrmini = i; if (maxi != n-1) i = ptrn-1; ptrn-1 = ptrmaxi; ptrmaxi = i; if (maxi = 0 & mini = n-1) i = ptrmaxi; ptrmaxi = ptrmini; ptrmini = i; (3)#include 3int strLength (char *);int main() static char str81; gets(str); printf(string %s length:%3dn,str,strLength(str) ; system(Pause); return 0;int strLength (char *s) char *p=s; while (*p) p+ ; return (p-s) ;(4)#include #define M 3#define N 4void Transpose (int (*a)N,int (*T)M);int main( ) static int aMN,TNM; int i,j; for( i = 0; i M; i+ ) for( j = 0; j N; j+ ) scanf( %d,&aij ); printf(n=Oringinal Matrix Start=n); for( i = 0; i M; i + ) for( j = 0; j N; j+ ) printf( %4d,aij ); printf(n); printf(n=Oringinal Matrix End=n); Transpose(a, T); printf(n=Transpose Matrix Start=n); for( i = 0; i N; i + ) for( j = 0; j M; j+ ) printf( %4d,Tij ); printf(n); 4 printf(n=Transpose Matrix End=n); return 0;void Transpose (int (*a)N,int (*T)M) int i,j; for( i = 0; i N; i+ ) for( j =0; j M; j+ ) Tij = aji;(5)#include int main() static char source81,target81; int result; gets(source); gets(target); result = Strcmp(source,target); if (result) if( result 0 ) printf(%s %sn,source,target); else printf(%s = %sn,source,t
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 仓鼠养殖合同样本
- 工程招标廉洁承诺书
- 美容院转让协议书范例
- 分期付款买卖合同样式二零二五年
- 两人合伙开发公司合同标准文本
- 无中介二手房买卖简单合同范例二零二五年
- 销售部提成管理制
- 校长聘用合同校长聘用合同范文
- 产品商标授权使用合同标准文本
- 造价咨询实施方案
- 初中信息技术教学中的项目式学习
- 部编版语文二年级下册第3单元核心素养教案
- 基于PLC的小区排水控制系统设计毕业论文
- DB43-T 1712-2019 银行业金融机构智能预警系统安全防范要求
- 2023年云南省接受军转干部安置考试试题
- 初三英语试卷分析失分原因和改进措施
- 关于在生产过程中物料流转的交接和管理规定
- 2022年高考真题及答案解析《历史、地理、政治》(湖北卷)
- 高中数学人教A版空间几何体(省一等奖)
- 把未来点亮歌词打印版
- 急性白血病急性髓系白血病课件
评论
0/150
提交评论