ImageVerifierCode 换一换
格式:DOCX , 页数:24 ,大小:24.02KB ,
资源ID:10518873      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/10518873.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(C语言课后习题答案.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

C语言课后习题答案.docx

1、C语言课后习题答案第一章 习题答案 一、选择题 15:BDCDA 610:DABBB 1112:CC 二、填空题 1、main() 2、函数首部 ,函数体 3、函数 4、编辑、编译、连接、运行 5、.cpp、.obj、 .exe 6、; 或 分号 三、编程题 #include /* 包含标准库的信息 */ void main() /* 定义名为main 的函数,它不接受参数值 */ /* main函数的语句都被括在花括号中 */ printf(hello, worldn); /* main 函数调用库函数printf 以显示字符序列,其中n代表换行符 */ 第二章 习题答案 一、选择题 15:

2、CBABB 610:CDCDD 1115:CADBC 1620:BDAAD 二、填空题 1、整型,实型,字符型,枚举类型 2、1 3、9 4、12353514 5、2,1 6、2,2 7、10 20 0 8、a=14 9、2,3,1 10、double 第三章 习题答案 一、选择题 15:CBBBC 610:DDDBB 二、填空题 1、控制语句,表达式语句, 复合语句 2、 ; 3、 4、1 5、a 6、c:dec=120,oct=170,hex=78,ASCII=x 7、32767,32767 8、10,A,10 9、3 3 10、 (1) 123.456001 (2) 123.456 (3

3、) 123.4560 (4) 8765.456700 (5) 8765.457 (6) 8765.4567 (7) 8765.4567 三、编程题 1、参考答案: #include void main() int a,b,c; long int u,n; float x,y,z; char c1,c2; a=3;b=4;c=5; x=1.2;y=2.4;z=-3.6; u=51274;n=128765; c1=a;c2=b; printf(n); printf(a=%2d b=%2d c=%2dn,a,b,c); printf(x=%8.6f,y=%8.6f,z=%9.6fn,x,y,z);

4、printf(x+y=%5.2f y+z=%5.2f z+x=%5.2fn,x+y,y+z,z+x); printf(u=%6ld n=%9ldn,u,n); printf(c1=%c or %d(ASCII)n,c1,c1); printf(c2=%c or %d(ASCII)n,c2,c2); 2、参考答案: #include void main() float a, b, c, t; printf(please input a,b,c:n); scanf (%f, %f, %f, &a, &b, &c); t=(a+b+c)/3; printf (average of %6.2f、%6.

5、2f and %6.2f is %6.2fn,a,b,c,t); 3、参考答案: #include main() int R, d; float s; printf(请输入圆的半径); scanf(%d,&R); d=2*R; c=2*3.14159*R; printf(d=%d,c=%fn,d,c); 4、参考答案: #include void main() int h, f, x, y; /* x为鸡的数量,y为兔的数量 */ printf(请输入鸡兔的总头数h,总脚数 f:); scanf(%d%d, &h, &f); x=(4*h-f)/2; y=(f-2*h)/2; printf(笼

6、中有鸡%d 只,有兔%d只。n, x, y); 第四章 习题答案 一、选择题 CDDDD CDBBC 二、填空题 1、&, | , !, ! , | | 2、(y%2 0) 3、1 4、(a+bc&a+cb&b+ca) 5、2 3 3 6、7 三、编程题 1、参考答案: #include void main() int x; scanf( %d,&x); if (x%5 0 & x%7 0) printf(yesn); else printf(non); 2、参考答案: #include void main( ) int a, b, c, max ; printf (请输入三个整数:%d%d%

7、dn); scanf( %d%d%d, &a, &b, &c ); if ( a=b ) if ( a=c ) max=a; else max=c; else if ( b=c ) max=b; else max=c; printf (n 最大数为:%dn,max ); 3、参考答案: #include void main ( ) float x , y ; printf( 请输入x 的值: ); scanf( %f, &x ) ; if (x1) y=1; else if (x10) y=2*x-1; else y=3*x-11; printf(y = %.2fn, y ); 4、参考答案:

8、 #include void main( ) int year; float money,rate,total; /* money:本金 rate:月利率 total:本利合计 */ printf(Input money and year =?); scanf(%f%d, &money, &year); /* 输入本金和存款年限 */ if(year 1) rate=0.00315; /* 根据年限确定利率 */ else if(year 2) rate=0.00330; else if(year 3) rate=0.00345; else if(year 5) rate=0.00375; e

9、lse if(year 8) rate=0.00420; else rate=0.0; total=money + money * rate * 12 * year; /* 计算到期的本利合计 */ printf( Total = %.2fn, total); 第五章 习题答案 一、选择题 15: ACCBA 610:ACDCB 二、填空题 1、(1) i=9 或 i10 (2) j%3!=0 2、7 3、(1) ch=ch+1、(2) printf(n) 三、编程题 1、参考答案: #include void main( ) int i=2; long p=1; do p=p*i; i=i+

10、2; while (i10); printf(2*4*6*8=%ldn,p); 2、参考答案: #include void main( ) int n=0; char c; c=getchar(); while(c!=n ) if(c=a&c=A&c=Z) n+; c=getchar(); printf(%dn,n); 3、参考答案: #include void main() int a,max; scanf(%d,&a); max=a; while(a!=0) scanf(%d,&a); if(maxa) max=a; printf(%d,max); 4、参考答案: #include voi

11、d main() int day = 0, buy = 2; float sum = 0.0, ave; do sum += 0.8 * buy; day+; buy *= 2; while (buy = 100); ave = sum / day; printf(“%f”, ave); 5、参考答案: #include void main() int f1,f2,f5,count=0; for(f5=0; f5=20; f5+) for(f2=0; f2 5: %4d 2: %4d 1: %4dn,+count,f5,f2,f1); printf(共有%d 种换法,count); 6、参考答

12、案: #include void main() int i,j,n; printf(nPlease Enter n:); scanf(%d,&n); for(i=1;i=n;i+) for(j=1;j=n-i;j+) printf( ); for(j=1;j=2*i-1;j+) printf(*); printf(n); 7、参考答案: #include void main() int i, j; float g, sum, ave; for (i=1; i=6; i+) sum = 0; for (j=1; j=5; j+) scanf(“%f”, &g); sum += g; ave =

13、sum / 5; printf(“No.%d ave=%5.2fn”, i, ave); 8、参考答案: #include void main() int n,t,number=20; float a=2,b=1,s=0; for(n=1;n=number;n+) s=s+a/b; t=a; a=a+b; b=t; printf(s=%9.6fn,s); 第六章 习题答案 一、选择题 15:CBABD 610:CDBCD 二、填空题 1、库函数(或系统函数) ,自定义函数 2、无参函数, 有参函数 3、传值方式 4、实参, 形参 5、1 3 6、max is 2 7、15 8、1,2,3 三、

14、编程题 1、参考答案: #include int is_prime( int a) int i,p=1; for( i=2;ia-1; i+) if (a%i 0) p=0; break; return (p); void main() int i=11; if (is_prime(i) printf(1); else printf(0); 2、参考答案: #include int gongyue(int num1,int num2) int temp,a,b; if(num1 =i 三、编程题 1、参考答案: #include void main() int i,a20,s,count; s

15、=count=0; for ( i=0; i20; i+) scanf(%d, &ai); for ( i=0; i20; i+) if (ai0) continue ; s+=ai; count+; printf(s=%dt count=%dn,s,count); 2、参考答案: #include void main() int a34,i,j,max; for (i=0;i3; i+) for (j=0; j4; j+) scanf(%d,&aij); max=a00; for (i=0;i3;i+) for (j=0;jmax) max=aij; printf(max=%dn,max);

16、 3、参考答案: #include void main() int a11=3,4,7,9,10,13,14,15,18,20; int i,j,n; scanf (%d,&n); i=0; while (i10) if (ni; j-) aj=aj-1; ai=n; break; i+; if (i=10) a10=n; for (i=0;i*s 5. *(+p) 三、编程题 1. 编程实现从键盘输入一个字符串, 将其字符顺序颠倒后重新存放, 并输出这个字符串。 #include #include void Inverse(char *pStr)? main() char str80? pr

17、intf(Input a string:n)? gets(str)? /*输入字符串*/ Inverse(str)? /*将存于 str 数组中的字符串逆序存放*/ printf(The inversed string is:n)? puts(str)? /*输出字符串*/ /*函数功能: 实现字符串逆序存放 函数参数: 字符指针变量,所指向的存储单元存放源字符串,逆序后的字符串也存放于此 返回值: 无*/ void Inverse(char *pStr) int len? char temp? char *pStart? /*指针变量 pStart 指向字符串的第一个字符*/ char *p

18、End? /*指针变量 pEnd指向字符串的最后一个字符*/ len = strlen(pStr)? /*求出字符串长度*/ for (pStart=pStr,pEnd=pStr+len?1? pStartpEnd? pStart+,pEnd?) temp = *pStart? *pStart = *pEnd? *pEnd = temp? 2.从键盘任意输入 10 个整数,用函数编程实现计算最大值和最小值,并返回它们所在数组 中的位置。 #include int FindMax(int num, int n, int *pMaxPos)? int FindMin(int num, int n,

19、 int *pMinPos)? main() int num10, maxValue, maxPos, minValue, minPos, i? printf(Input 10 numbers:n )? for (i=0? i10? i+) scanf(%d, &numi)? /* 输入 10 个数*/ maxValue = FindMax(num, 10, &maxPos)? /* 找最大值及其所在下标位置 */ minValue = FindMin(num, 10, &minPos)? /* 找最小值及其所在下标位置 */ printf(Max=%d, Position=%d, Min=%

20、d, Position=%dn, maxValue, maxPos, minValue, minPos)? /*函数功能:求 n个数中的最大值及其所在下标位置 函数入口参数:整型数组 num,存储 n个整数,整型变量 n,表示数组元素个数 函数出口参数:整型指针变量 pMaxPos,指向的地址单元存储最大值在数组中的下标位置 函数返回值: 最大值*/ int FindMax(int num, int n, int *pMaxPos) int i, max? max = num0? /*假设 num0为最大*/ *pMaxPos = 0? /*假设最大值在数组中的下标位置为 0 */ for (i = 1? i max) max = numi? *pMaxPos = i? return max ? /*函数功能: 求 n个数

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1