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

上传人:宝路 文档编号:21534358 上传时间:2017-11-24 格式:DOC 页数:16 大小:227.06KB
返回 下载 相关 举报
C语言程序设计教程答案杨路明郭浩志_第1页
第1页 / 共16页
C语言程序设计教程答案杨路明郭浩志_第2页
第2页 / 共16页
C语言程序设计教程答案杨路明郭浩志_第3页
第3页 / 共16页
C语言程序设计教程答案杨路明郭浩志_第4页
第4页 / 共16页
C语言程序设计教程答案杨路明郭浩志_第5页
第5页 / 共16页
点击查看更多>>
资源描述

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

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

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

3、符: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 键存盘。习题 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=Aendaabcc abc3、4、(1):9,11,9,10(2):3,1,0,0(3):11,19,31,1

5、5、(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,&c2);7、printf(a+b=%dn,a+b);printf(a-b

6、=%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);elseprintf(you input number is error!);9、void main() int n;

7、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);elseprintf(you input the number is error!n);习题 41: 02: 203: (x20)|(xvoid main() char a,b,t1,t2;scanf(%c,%c,&a,&b);t1=ab?a:b;t2=avoid main() int temp1=0,temp2=0,

8、x,y,i=1;printf(Please input (x,y): );scanf(%d,%d,&x,&y);while(i*y) shang=%d,yushu=%d,x,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)void main() int temp=0,month,year;printf(Please input (year,month): );scanf(%d,%d,&year,&mon

9、th);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)

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&xvoid main() int x,y;scanf(%d,&x);if(x-5) if(x=0)y=x;else if(x0&xvoid main() int x,y,i;scanf(%d,&x);if(x-5) if(x=0)i=1;else if(x0&x

11、= A & ch = a & ch = 0 & ch = A & ch = a & ch 500)break;printf(the %d years later complete!n,count);6、void main()int i,temp=0,bit=0;for(i = 1 ; i int main(void)int steps = 29, i = 1;while ( steps % 7 )steps = (30 * +i) - 1;printf(Total steps: %dn, steps);return 0;8、main()int i,j,k,n;printf(the narcis

12、sus number is:n);for(n=100;n=nleft&b#include void main()int n;long k = 1;float e = 1;n = 1;clrscr();while ( fabs(1.0/k) = 0.000001)n+;e = e+ 1.0/k;k = k * n;printf(%fn,e);15、#include math.hmain()float x0,x1,x2,f0,f1,f2;x1=-10;f1=2*x1*x1*x1-4*x1*x1+3*x1;x2=10;f2=2*x2*x2*x2-4*x2*x2+3*x2;do x0=(x1+x2)/

13、2;f0=2*x0*x0*x0-4*x0*x0+3*x0;if(f0*f1)1e-6);printf(_2*x*x*x-4*x*x+3*x=0_n);printf(the root is %fn,x0);习题 61、#includeint divisor(int a,int b) int r;while(r=a%b)!=0) a=b;b=r;return b;int multiple(int a,int b) int d;d=divisor(a,b);return a*b/d;void main() int a,b,c,d;printf(intput (a,b): );scanf(%d,%d,

14、&a,&b);c=divisor(a,b);d=multiple(a,b);printf(ndivisor=%dttmultiple=%d,c,d);2、#includevoid tongji(char a) int b3=0,0,0,i=0;while(ai!=0)if(ai=65)|(ai=97)b0+;else if(ai=48) b1+;elseb2+;i+;printf(zimu have: %d; shuzi have: %d; qita have: %d,b0,b1,b2);getch();void main() char a100;printf(Please input a s

15、tring: );gets(a);tongji(a);3、#includeint flower(int n) int x=0,i,j,k;i=(n%10); j= (n/10%10);k=(n/100);x=i*i*i+j*j*j+k*k*k;if(x=n) return 1;else return 0;void main() int i,n;printf(Please intput n: );scanf(%d,&n);if(n999|n#define SWAP(a,b) t=b;b=a;a=t;main() float x,y,t;printf(Enter two number (x,y): );scanf(%f,%f,&x,&y);SWAP(x,y);printf(nnExchanged:x=%f,y=%f,x,y);getch();5、#includeint fib(int n) int p;if(

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 中学教育 > 试题/考题

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