C语言程序设计教程答案杨路明郭浩志

上传人:鲁** 文档编号:486180116 上传时间:2023-05-30 格式:DOCX 页数:54 大小:52.64KB
返回 下载 相关 举报
C语言程序设计教程答案杨路明郭浩志_第1页
第1页 / 共54页
C语言程序设计教程答案杨路明郭浩志_第2页
第2页 / 共54页
C语言程序设计教程答案杨路明郭浩志_第3页
第3页 / 共54页
C语言程序设计教程答案杨路明郭浩志_第4页
第4页 / 共54页
C语言程序设计教程答案杨路明郭浩志_第5页
第5页 / 共54页
点击查看更多>>
资源描述

《C语言程序设计教程答案杨路明郭浩志》由会员分享,可在线阅读,更多相关《C语言程序设计教程答案杨路明郭浩志(54页珍藏版)》请在金锄头文库上搜索。

1、C语言程序设计教程习题答案总主编 杨路明主审 郭浩志文件摘自 CSDN习题11、算法描述主要是用两种基本方法:第一是自然语言描述,第二是使用专用工具进行算法描述2、c语言程序的结构如下: 1、c语言程序由函数组成,每个程序必须具有一个main函数作为程序的主控函数。 2、/*与*/之间的内容构成c语言程序的注释部分。 3、用预处理命令#include可以包含有关文件的信息。 4、大小写字母在c语言中是有区别的。 5、除main函数和标准库函数以外,用户可以自己编写函数,程序一般由多个函数组成,这些函数制定实际所需要做的工作。 例如: void main() int a,b,c,s; a=8;b

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

3、_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 you very good * (2): please input three number;5,7,8 max number is:87、main8、User screen、Alt+F59、标识符必须是字母或下划线开头,大小写字

4、母含义不同。由数字、字母和下划线组成; 关键字是一种语言中规定具有特定含义的标识符。关键字不能作为变量或函数名来使用,用户只能根据系统的规定使用它们。10、选择主菜单File项下拉子菜单中Save项或直接按F2键存盘。习题21、符合C语法规定的常数为:0x1e、abn、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=%db=%cendn,a,b); 结果如下:a=3b=Aend aabcc abc3、4、(1):9,11,

5、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习题31、输入函数scanf的参数错误,应该为:scanf(%f,&k);2、|1234 1234 |3、ff104、1,3,15、原字符串 左边加空格再加字符串本省,字符个数总和为5个6、scanf(%d,%d,%c,%c,&a1,&a2,&c1,

6、&c2);7、printf(a+b=%dn,a+b); printf(a-b=%dn,a-b); printf(a*b=%dn,a*b); printf(a/b=%dn,a/b); printf(float)a/b=%fn,(float)a/b); printf(a%b=%dn,a%b);8、void main() float r; float s,c; printf(please input the number:); scanf(%f,&r); if(r=0) s = 3.14*r*r; c = 2*3.14*r; printf(s = %f, c = %fn,s,c); elseprin

7、tf(you input number is error!); 9、void main() int n; printf(please input the number:); scanf(%d,&n); if(n=100 & n c | a+c b | b+c a) s = (a+b+c)/2; Area = sqrt(s*(s-a)*(s-b)*(s-c); printf(%fn,Area); else printf(you input the number is error!n);习题41:02:203: (x20)|(x-100)4:*a=25,b=14,c=16*5:376:if(a=b

8、) printf(1);else printf(2);7、#includevoid main()char a,b,t1,t2;scanf(%c,%c,&a,&b);t1=ab?a:b;t2=ab?a:b;if(t1-t2)%2=0)printf(%c,%c,a+1,b+1);elseprintf(%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,&x,&y);while(i*y) shang=%d,yushu=%d,x,

9、y,temp2,x-y*temp2);getch();9、#includevoid main()float x,y,m=0,n=0;scanf(%f,%f,&x,&y);n=(x-2)*(x-2);m=(y-2)*(y-2);if(m+n)=1)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;printf(Please input (year,month): );scanf(%d,%d,&

10、year,&month);if(year%400=0)|(year%4=0&year%100!=0)temp=1;if(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,month);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,&x);if(x-5)y=x-1;else if(x=0)y=x;else if(x0&x8)y=x+1;printf(%d,y);getch();方法二:#includevoid main()int x,y;scanf(%d,&x);if(x-

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

当前位置:首页 > 办公文档 > 教学/培训

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