c语言程序设计教程_杨路明__课后习题答案

上传人:小** 文档编号:46985299 上传时间:2018-06-28 格式:DOCX 页数:28 大小:26.27KB
返回 下载 相关 举报
c语言程序设计教程_杨路明__课后习题答案_第1页
第1页 / 共28页
c语言程序设计教程_杨路明__课后习题答案_第2页
第2页 / 共28页
c语言程序设计教程_杨路明__课后习题答案_第3页
第3页 / 共28页
c语言程序设计教程_杨路明__课后习题答案_第4页
第4页 / 共28页
c语言程序设计教程_杨路明__课后习题答案_第5页
第5页 / 共28页
点击查看更多>>
资源描述

《c语言程序设计教程_杨路明__课后习题答案》由会员分享,可在线阅读,更多相关《c语言程序设计教程_杨路明__课后习题答案(28页珍藏版)》请在金锄头文库上搜索。

1、 C C 语言程序设计教程语言程序设计教程 杨路明杨路明 课后习题答案课后习题答案 北京邮电大学出北京邮电大学出版社版社第一章第一章1、算法描述主要是用两种基本方法:第一是自然语言描述,第二是使用专用工具进行算法描述2、c 语言程序的结构如下:c 语言程序由函数组成,每个程序必须具有一个 main 函数作为程序的主控函数。“/*“与“*/“之间的内容构成 c 语言程序的注释部分。用预处理命令#include 可以包含有关文件的信息。大小写字母在 c 语言中是有区别的。除 main 函数和标准库函数以外,用户可以自己编写函数,程序一般由多个函数组成,这些函数制定实际所需要做的工作。例如:void

2、 main()int a,b,c,s;a=8;b=12;c=6;s=a b*c;printf(“s=%d“,s);3、c 语言的特点:c 语言具有结构语言的特点,程序之间很容易实现段的共享;c 语言的主要结构成分为函数,函数可以在程序中被定义完成独立的任务,独立地编译成代码,以实现程序的模块化。c 语言运算符丰富,运算包含的范围很广;c 语言数据类型丰富。c 语言允许直接访问物理地址,即可直接对硬件进行操作,实现汇编语言的大部分功能;c 语言语法限制不太严格,程序设计自由度大,这样是 c 语言能够减少对程序员的束缚;用 c 语言编程,生成的目标代码质量高,程序执行效率高,可移植性好;4、合法标

3、识符:AB12、leed_3、EF3_3、_762、PAS、XYZ43K2不合法标识符:a*b2、8stu、D.K.Jon、if、ave#xy、#_DT5、C.D5、F2:将当前编辑器中文件存盘F10:调用主菜单F4:程序运行到光标所在行Ctrl F9:当前编辑环境下,进行编译、连接且运行程序;Alt F5:将窗口切换到 DOS 下,查看程序运行结果6、(1):*welcome youvery good*(2):please input three number;5,7,8max number is:87、main8、User screen、Alt F59、标识符必须是字母或下划线开头,大小写

4、字母含义不同。由数字、字母和下划线组成;关键字是一种语言中规定具有特定含义的标识符。关键字不能作为变量或函数名来使用,用户只能根据系统的规定使用它们。10、选择主菜单 File 项下拉子菜单中 Save 项或直接按 F2 键存盘。第二章第二章1、符合 C 语法规定的常数为:0x1e、“ab“、1.e52、(1):错误如下:int x,y=5,z=5,aver;x=7;aver = (x y x)/3;结果如下:AVER=5(2):错误如下:char c1=a,c2=b,c3=c;printf(“a=?=_end“,a,b);结果如下:a=3b=A“end“aabcc abc3、4、(1):9,

5、11,9,10(2):3,1,0,0(3):11,19,31,15、(1):0(2):0(3):9.500000(4):90(5):10(6):10(7):65(8):4(9):4.500000(10):1(11):0(12):20(13):06、(5)7、求 x 的绝对值8、c(max=ab?a:b)?c:max;9、B10、D第三章第三章1、输入函数 scanf 的参数错误,应该为:scanf(“%f“,2、|1234 1234 |3、ff104、1,3,15、原字符串左边加空格再加字符串本省,字符个数总和为 5 个6、scanf(“%d,%d,%c,%c“,7、printf(“a b=%

6、d“,a b);printf(“a-b=%d“,a-b);printf(“a*b=%d“,a*b);printf(“a/b=%d“,a/b);printf(“(float)a/b=%f“,(float)a/b);printf(“a%b=%d“,a%b);8、void main()float r;float s,c;printf(“please input the number:“);scanf(“%f“,if(r=0)s = 3.14*r*r;c = 2*3.14*r;printf(“s = %f, c = %f“,s,c);elseprintf(“you input number is er

7、ror!“);9、void main()int n;printf(“please input the number:“);scanf(“%d“,if(n=100 elseprintf(“you input number is error!“);10、void main()int i,j,k;scanf(“%d,%d,%d“,(i%2 != 0?1:0) (j%2 != 0?1:0) (k%2 != 0?1:0) = 2?printf(“YES“):printf(“NO“);11、void main()char a;scanf(“%c“,printf(“%c,%c,%c“,a-1,a,a 1);

8、printf(“%d,%d,%d“,a-1,a,a 1);12、void main()float a,b,c,s,Area;scanf(“%f,%f,%f“,if(a b c | a c b | b c a)s = (a b c)/2;Area = sqrt(s*(s-a)*(s-b)*(s-c);printf(“%f“,Area);elseprintf(“you input the number is error!“);第四章第四章1: 02: 203: (x20)|(x4: *a=25,b=14,c=16*5: 376: if(aelse printf(“2“);7、#includevoi

9、d main()char a,b,t1,t2;scanf(“%c,%c“,t1=ab?a:b;t2=aif(t1-t2)%2=0)printf(“%c,%c“,a 1,b 1);else printf(“%c,%c“,a-1,b-1);getch();8、#includevoid main()int temp1=0,temp2=0,x,y,i=1;printf(“Please input (x,y): “);scanf(“%d,%d“,while(i*y)if(x=(i*y) temp1=1;break;temp2=i;i ;if(temp1)printf(“%d / %d = %d“,x,y

10、,i);elseprintf(“%d / %d- shang=%d,yushu=%d“,x,y,temp2,x-y*temp2);getch();9、#includevoid main()float x,y,m=0,n=0;scanf(“%f,%f“,n=(x-2)*(x-2);m=(y-2)*(y-2);if(m n)printf(“(%.3f,%.3f)In the yuan“,x,y);elseprintf(“(%.3f,%.3f)out of the yuan“,x,y);getch();10、#includevoid main()int temp=0,month,year;print

11、f(“Please input (year,month): “);scanf(“%d,%d“,if(year0=0)|(year%4=0if(month=2)if(temp)printf(“%d year %d month have 29 “,year,month);else printf(“%d year %d month have 28 “,year,month);else if(month%2=0)printf(“%d year %d month have 30 “,year,month);else printf(“%d year %d month have 31 “,year,mont

12、h);getch();11、switch(a/10)case 5:m=4;break;case 4:m=3;break;case 3:m=2;break;case 2:m=1;break;default:m=5;12、方法一:#includevoid main()int x,y;scanf(“%d“,if(x-5)y=x-1;else if(x=0)y=x;else if(x0printf(“%d“,y);getch();方法二:#includevoid main()int x,y;scanf(“%d“,if(x-5)if(x=0)y=x;else if(x0printf(“%d“,y);el

13、se printf(“Input error!“);getch();方法三:#includevoid main()int x,y,i;scanf(“%d“,if(x-5)if(x=0)i=1;else if(x0else i=4;switch(i)case 1:y=x;printf(“%d“,y);break;case 2:y=x 1;printf(“%d“,y);break;case 3:y=x-1;printf(“%d“,y);break;case 4:printf(“Input error!“);break;getch();第五章第五章1、void main()int n,value;i

14、nt i,count=0;float average = 0;long int sum = 0;scanf(“%d“,for(i = 0; i scanf(“%d“,if(value%2 = 0)sum =value;count ;average = sum / (float)count;printf(“the average is %f“,average);2、#include “stdio.h“void main()char ch;int zm = 0, sz = 0;ch = getchar();while(ch != *)if(ch = A if(ch = 0 ch = getchar

15、();printf(“zm = %d ; sz = %d“,zm,sz);3、void main()long i_value;int sum = 0;int temp = 0;scanf(“%ld“,if(i_value for(;)temp = i_value_;i_value = i_value/10;sum =temp;printf(“%d “,temp);if(i_value = 0)break;printf(“=%d“,sum);=%d“,sum);4、#include “stdio.h“void main()char ch;ch = getchar();while(ch != .)if(ch = A putchar(ch);else if(ch = a putchar(ch);elseputchar(ch);ch = getchar();printf(“);5、void main()float sum = 200;int count = 0;for(;)sum = sum sum*0.045;count ;if(sum 500)break;printf(“the %d years later complete!“,count);6、void main()int i,temp=0,bit=0;for(i = 1 ; i if(i%3 = 0)temp = i

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 宣传企划

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号