版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、.程序设计技术(第三版)习题参考答案习题1一、单项选择题DADDDB CCD(注:第7小题无正确选项,正确答案为-12)二、填空题 主 main x=x*(x+b) 普通、格式、分隔和转义 指定输出数据格式 void main() how are you! 三、阅读程序题1.9,11,9,10 2.2,-1,-13.aa bb cc abc4.2,25.57 5 767.5864000,-789.12402367.5864000, -7.89e+002 67,86, -789.12,67.5864000, -789.124023, 67.5864000, -789.1240236.758640
2、e+001, -7.89e+002A,65,101,411234567,4553207,12d68765535,177777,ffff,65535COMPUTER, COM.6. a + c = 102a + c = ff + m = 17.950000a + m = 17.650000c + f = 102.300000double = 1746.150019四、程序设计题/xt010401.cpp#include #define PI 3.1415926void main()double r,h;printf(请输入半径r和高h:);scanf(%lf,%lf,&r,&h);printf(
3、圆半径: %lfn,2*PI*r);printf(圆面积:%lfn,PI*r*r);printf(圆球表面积:%lfn,4*PI*r*r);printf(圆球体积:%lfn,4.0/3*PI*r*r);printf(圆柱体积:%lfn,PI*r*r*h);/xt010402.cpp#include void main()int c;printf(Input a character:);c=getchar();printf(%ct%dn,c,c);/xt010403.cpp#include void main()int x,y,h=30,f=90;x=(4*h-f)/2;y=(f-2*h)/2;
4、printf(鸡:%d, 兔:%dn,x,y);/xt010404.cpp#include #include void main()double a,b,c,s,area;printf(请输入三角形的三条边长(注意三条边长应能够构成三角形):);scanf(%lf,%lf,%lf,&a,&b,&c);s=(a+b+c)/2;area=sqrt(s*(s-a)*(s-b)*(s-c);printf(三角形的面积是: %lfn,area);/xt010405.cpp#include void main()double f,c;printf(请输入华氏温度:);scanf(%lf,&f);c=5.0
5、/9.0*(f-32);printf(与华氏温度%.2lf对应的摄氏温度是:%.2lfn,f,c);/xt010406.cpp#include void main()char c1,c2,c3,c4,c5;printf(请输入需加密的字符串(5个字符):);c1=getchar();c2=getchar();c3=getchar();c4=getchar();c5=getchar();printf(加密后的字符串是:);putchar(c1+5);putchar(c2+5);putchar(c3+5);putchar(c4+5);putchar(c5+5);printf(n);习题2一、 单项
6、选择题CBADC CCAAC二、填空题 a+b=0&a*b!=0 逻辑与 逻辑或 continue (c= getchar ()!=n %c三、阅读程序题答案:答案:该程序所完成功能的函数关系为:答案: 答案: 答案: 答案: 四、程序设计题/* xt020401.cpp */#include void main()int num; printf(* Input num: *n); scanf(%d,&num); if(num%3=0&num%5=0&num%7=0) printf(* YES ! *n); else printf(* NO ! *n);/* xt020402.cpp */#i
7、nclude void main()int h=0;float x,y,x0=2,y0=2,d1,d2,d3,d4;printf(* input: x,y *n);scanf(%f,%f,&x,&y); d1=(x-x0)*(x-x0)+(y-y0)*(y-y0); /*点(x,y)到各中心点的距离*/ d2=(x-x0)*(x-x0)+(y+y0)*(y+y0); d3=(x+x0)*(x+x0)+(y-y0)*(y-y0); d4=(x+x0)*(x+x0)+(y+y0)*(y+y0); if(d1=1|d2=1|d3=1|d4=1) h=15; printf(x=%f, y=%fn,x,
8、y); printf(h=%dn,h);/* xt020403.cpp */#include void main() int i,j,k,n; for(n=100;n=999;n+)i=n/100; j=n/10-i*10; k=n%10; if(n=i*i*i+j*j*j+k*k*k)printf(%dn,n); /* xt020404.cpp */#include #include #define EPS 1.0e-6void main() float e=1,t; long int j=1,n=1; do j=j*n; t=1.0/j; e=e+t; n+; while ( fabs(t
9、) = EPS ); printf(e=%fn,e); /* xt020405.cpp */#include void main()int num=1; do if(num+3)%5=0&(num-3)%6=0) break; num+=1; while(1);printf(num=%dn,num);/* xt020406.cpp */#include void main() int num; for(num=1;num=99;num+) if(num*num%10=num|num*num%100=num) printf(%4d,%5d,num,num*num); printf(n);/* x
10、t020407.cpp */#include void main() int n,k=1; float s=0; for(n=1;n=10000;n+) s=s+1.0/(2.0*n-1)*k; k=-k; printf(PI=%fn,4*s);/* xt020408.cpp */#include void main() int n10,n5,n2,n1; for(n10=1;n10=9;n10+) for(n5=1;n5=17;n5+) for(n2=1;n2=1&n10*10+n5*5+n2*2+n1=100) printf(n10=%d,n5=%d,n2=%d,n1=%dn,n10,n5
11、,n2,n1); /* xt020409.cpp */#include void main()float sn=100,hn=sn/2; int n=2; while(n=10) sn+=2*hn; hn=hn/2; n+; printf(%f,%fn,sn,hn);/* xt020410.cpp */#include void main() int day,x1,x2=1; for(day=9;day0;day-) x1=(x2+1)*2; x2=x1; printf(Total=%dn,x1);习题3单项选择题BBCAC DDABB填空题 9 0 10 x 一致 n/2 sum+a sum
12、/n三、阅读程序题1. 2 4 62. s=303. 5 9 45 8 424. lanuge5. 8 1 6 3 5 7 4 9 26. max=10,row=2,colum=1四、程序设计题/xt030401.cpp#include #include #include void main(void) int num10, a; srand(unsigned)time(NULL); printf(请输入一个2位数,试试您是否能中奖:); scanf(%d,&a); for(int i=0;i10;i+) numi = (rand()+10)%100; if(a = numi) printf(
13、猜中一个数 %d 下标是 %d,a,i); printf(-n); for( i=0; i10; i+) printf(%dt ,numi);/xt030402.cpp#include #include #include void main(void) int a5=23,45,60,67,88,x,i,j,yes=0; for(i=0;i5;i+) printf(%d,ai); printf(nwhich number do you want to delete?n); scanf(%d,&x); for(i=0;i5;i+) if(ai=x) yes=1; for(j=i;j5;j+) a
14、j=aj+1; if(yes=1) for(i=0;i4;i+) printf(%d,ai); else printf(The number you want doesnt exist); /xt030403.cpp#include #include #include #define SIZE 1000void main() int x,aSIZE,size,sum=0; srand(unsigned)time(NULL); while(size=rand()%1000)200); printf(nRandomiz list size(1000):%d,size); printf(nAuto
15、make a %d size of list:n,size); for(x=0;xsize;x+) ax=rand()%1000 ; printf(%dt,ax); sum+=arrx; printf(nThe sum of array elements is %d, sum);/xt030404.cpp#include #include #include #define SIZE 100void main() int x,aSIZE,max=0,min=1000,b1,b2;srand(unsigned)time(NULL); printf(nAuto make a %d size of l
16、ist:n,size); for(x=0;xSIZE;x+) ax=rand()%1000 ; printf(%dt,ax); for(x=0;xmax) max=ax,b1=x; if(axmin) min=ax,b2=x; printf(nThe array elements max= %d in %d n min=%d in %dn,max,b1,min,b2);/xt030405.cpp#include #define SIZE 100#define KIND 5void main() int x,y,len,totalKIND+1; int a=1,1,1,1,2,2,2,3,5,5
17、,5,5,1,1,3,3,3,3,3,2,2,2,5,5,5; len=sizeof(a)/sizeof(a0); for(x=0;xKIND+1;x+) totalx=0 ; for(y=1;yKIND+1;y+) for(x=0;xlen;x+) if (ax=y) totaly+; printf(nThe list kinded:n); for(x=0;xlen;x+) printf( %d ,ax); printf(nThe total result: ); for(x=1;xKIND+1;x+) printf( %d-%d, ,x,totalx);/xt030406.cpp#defi
18、ne N 26#include int main(void) static int aN+1,bN+1; int i,j,s,m,p; scanf(%d%d,&s,&m); for (i=1;i=N;i+) ai=i; i=s-1;j=0;p=0; while (pN) i-=N; if (ai=0) i+;goto bh; j+; if (j%m=0) p+;bp=ai;ai=0;j=0; for (i=1;i=N;i+) printf(%3d,bi); printf(n);/xt030407.cpp#include voidmain()inti,j,s=0,ave,v3;staticint
19、a53=80,75,92,61,65,71,59,63,70,85,87,90,76,77,85;for(i=0;i3;i+) for(j=0;j5;j+) s=s+aji; vi=s/5; s=0;ave=(v0+v1+v2)/3;printf(math:%dnclanguag:%dndbase:%dn,v0,v1,v2);printf(total ave:%dn,avel);/xt030408.cpp#include void main() int i,j,a1010, b=1,2,3,4,5,6,7,8,9,10; for(i=0;i10;i+) a0i=bi; for(i=1;i10;
20、i+) for(j=0;jj) aij=aji;else aij=ai-1j-1;for(i=0;i10;i+) for(j=0;j10;j+) printf(%dt,aij); printf(n); /xt030409.cpp#include #include #include #define SIZE 5000#define N 7void main() int x,y,aN=0,0,0,0,0,0,0,s;srand(unsigned)time(NULL); x=0; while(x0&s7) as+; x+; printf(nRandomiz 1-6 list n); for(x=1;
21、xN;x+) s=ax*0.07; for(y=0;ys;y+)printf(%d,x);printf(t%dt%2.1f%n,ax,(float)ax*100/SIZE); /xt030410.cpp#include #define N 20int main() int x,s,tag; char aN; printf(Please input numbers and its length less then %d:,N-1); s=1; while(sN) scanf(%c,&as); if(as=10)break; s+; printf(nThe numbers is :n); for(
22、x=1;xs;x+) printf(%c,ax); tag=0; for(x=1;xs/2;x+) if(ax!=as-x) tag=1; break; if(tag=0)printf(nThe number is palindrome!); else printf(nThe number isnt palindrome!);习题4一、 单项选择题ABACA BCBDD二、 填空题 主 main函数 main函数 个数 类型 顺序 函数类型 float(float x,int n) f(x,n) x*f(x,n-1) 三、阅读程序题1 x=5,y=252. y=170.03. s1=3.14,
23、s2=5.14 4. 5002 5. 5,3 6. 3.00,1.00,0.25四、程序设计题/xt040401.cpp #include void main( ) void dis(int n);int n;scanf(%d,&n);dis(n); void dis(int n) int k0,k,sum,i;k0=1;dok=k0;sum=0;for(i=1;i=n;i+)sum=sum+k;k=k+2;if(sum=n*n*n)break;elsek0=k0+2;while(1);for(i=1;i=n;i+)printf(%5d,k0);k0=k0+2;/xt040402.cpp#in
24、clude void main( )float h(int n,float x);int n;float x;scanf(%d,%f,&n,&x);printf(h(%d,%f)=%f,n,x,h(n,x);float h(int n,float x)if(n=0)return 1;else if(n=1)return(2*x);elsereturn(2*x*h(n-1,x)-2*(n-1)*h(n-2,x);/xt040403.cpp#include void main()int f(int n);int i;for(i=2;i=1000;i+)if(f(i)printf(%6d,i);in
25、t f(int n)if(n=n*n%10|n=n*n%100|n=n*n%1000)return 1;elsereturn 0;/xt040404.cpp#include void main( )long fun(int a,int n);int k,n;scanf(%d,%d,&k,&n);printf(%ldn,fun(k,n);long fun(int a, int n)int j;long s=0,t=0;for(j=1;j=n;j+)t=t*10+a;s=s+t;return s;/xt040405.cpp#include #include void main()int num,m
26、iddle1,middle2;int detect(int d);printf(Please input a positive even number(=6):);scanf(%d,&num);for(middle1=2;middle1=num/2;middle1+=1)if(detect(middle1)middle2=num-middle1;if(detect(middle2)printf(%d=%d+%dn,num,middle1,middle2);break;int detect(int d)int i;for(i=2;i=sqrt(d*1.0);i+)if(d%i=0)return(
27、0);return 1;/xt040406.cpp#include void main()float f(float x,int n);float x,an;int n;scanf(%f,%d,&x,&n);an=f(x,n);printf(an=%fn,an);float f(float x,int n)if(n=0)return 1;elsereturn x/n*f(x,n-1);/xt040407.cpp#include void main()float f(float x,int n);float x,fn;int n;scanf(%f,%d,&x,&n);fn=f(x,n);prin
28、tf(an=%fn,fn);float f(float x,int n)if(n=0)return 1;else if(n0)return x*f(x,n-1);elsereturn f(x,n+1)/x;/xt040408.cpp#include void main( )void f(int n);int n; scanf(%d,&n);while(n=0)scanf(%d,&n);f(n);void f(int n)if(n/10=0)putchar(n%10+0);elseputchar(n%10+0);f(n/10);/xt040409.cpp#include void main( )
29、void f(int n);int n; scanf(%d,&n);while(n=0)scanf(%d,&n);f(n);void f(int n)if(n/10)f(n/10);putchar(n%10+0); /xt040410.cpp#include void main()int f(int n);int n;for(n=2;n=1000;n+)if(f(n)printf(%d is a 完数n,n);int f(int n)int i,s=0;for(i=1;in;i+)if(n%i=0)s=s+i;if(s=n)return 1;elsereturn 0;习题5一、单项选择题AAC
30、CA DDACB二、填空题 “char *func1()”定义一个返回字符指针值的函数,“char(*func2)()”定义一个指向函数的指针 一个返回值为单精度类型指针的函数名; (*p)(a,b,c) findmin (*f)(x,y,z); 三、阅读程序题112025,4,3344155112649111131315/xt050401.cpp#include stdio.hvoid main()void f(int,int,int);int a,b,c;void (*p)(int,int,int);scanf(%d%d%d,&a,&b,&c); p=f;(*p)(a,b,c); void
31、 f(int x,int y,int z) int t;if(xy)t=x,x=y,y=t;if(yz)t=z,z=y,y=t;if(xy)t=x,x=y,y=t; printf(%5d%5d%5dn,x,y,z);/xt050402.cpp#include int max(int a,int b)if(ab)return a;else return b;void main()int max(int a,int b);int(*pmax)(int,int);int x,y,z;pmax=max;printf(input two numbers:n);scanf(%d%d,&x,&y);z=(*
32、pmax)(x,y);printf(maxmum=%d,z);/xt050403.cpp#include stdio.hvoid gcd(int x,int y)int temp;while(y!=0)temp=x%y;x=y;y=temp;printf(The greatest common divisor is:%dn,x);void lcm(int x,int y)int temp,m,n;m=x;n=y;while(x!=0)temp=y%x;y=x;x=temp;printf(The lowest common multiple is:%dn,m*n/y);void main()in
33、t a,b;void (*p)(int,int);printf(Please input a and b:);scanf(%d%d,&a,&b);if(ab)p=gcd;elsep=lcm;(*p)(a,b);/xt050404.cpp#include stdio.hvoid main()int x,y; int sum(int,int),diff(int,int),product(int,int); void mma(int x,int y,int s(int,int); printf(Please input x,y:n); scanf(%d%d,&x,&y); printf(The su
34、m of x and y is:); mma(x,y,sum); printf(The difference of xa nd y is:); mma(x,y,diff); printf(The product of x and y is:); mma(x,y,product); int sum(int x,int y) return x+y;int diff(int x,int y) return x-y;int product(int x,int y)return x*y;void mma(int a,int b,int s(int,int)int w;w=s(a,b);printf(%d
35、n,w);/xt050405.cpp#include double func1(int x),func2(int y);void main()double (*fptr)(int); /*定义指向函数的指针变量fptr*/int n;printf(input a number:);scanf(%d,&n);if(n1) if(n%2=0)fptr=func1;/*n为偶数,指针变量ptr指向函数func1()*/elsefptr=func2; /*n为奇数,指针变量ptr指向函数func2()*/printf(value=%9.4fn,(*fptr)(n);else printf(error!
36、n);double func1(int x)int k;double value;value=1.0;for(k=2;k=x;k=k+2)value=value+1/(double)k; return value;double func2(int y)int k;double value;value=1.0;for(k=3;k=y;k=k+2)value=value+1/(double)k; return value;/xt050406.cpp#include stdio.h#include math.hvoid main()int n,yinzi(int),(*f)(int);f=yinzi
37、;printf(input a number n:);scanf(%d,&n);if(*f)(n)=2)printf(n%d is a prime number.,n);elseprintf(n%d is not a prime number.,n); int yinzi(int x)int i,k=0,q=(int)sqrt(x);for(i=1;i=q;i+)if(x%i=0)k+=2; printf(%5d%5d,i,x/i);return k;/xt050407.cpp#include #include double f1(double x)return x*x*log(x);doub
38、le f2(double x)return x*sin(x);double f3(double x)return x/exp(x);double collect(double (*p)(double x),double a,double b,double n)int i;double h,area;h=(b-a)/n;area=(*p)(a)+(*p)(b)/2.0;for(i=1;i=eps);if(m=0) return (0);return (1);double f1(double x)return(1.0+atan(x);double f2(double x)return(0.5*co
39、s(x);double f3(double x)return(6.0+3*x-x*x)/4);/* x=(6+3*x-x*x)/4*/void main()double x,(*p)(double);x=1.0;p=f1;if(root(&x,50,0.00001,p)printf(x1=%fn,x);p=f2;if(root(&x,50,0.00001,p)printf(x1=%fn,x); p=f3;if(root(&x,50,0.00001,p)printf(x1=%fn,x); /xt050409.cpp#include stdio.hint * f(int p,int q,int m
40、)int i;for(i=0;im;i+)qi=pi*pi;return q;void main()int a6=1,2,3,4,5,6,i,*k;int b6;k=f(a,b,6);for(i=0;i6;i+)printf(%5d,ki);/xt050410.cpp#include #include void main()int wanshu(int x);int *ptr;ptr=(int *)malloc(sizeof(int);if(ptr=NULL)printf(Failed to create a new object.); exit(0); scanf(%d,ptr); if(w
41、anshu(*ptr)printf(%d is a 完数:,*ptr); elseprintf(%d is not a 完数:,*ptr);free(ptr);int wanshu(int x)int i=1,sum=0;while(ix)if(x%i=0)sum+=i;i+;if(sum=x)return 1;elsereturn 0;习题6一、 单项选择题BDACD CACAD二、 填空题 是其值可以是二级地址(指针) 是其值可以是多级地址址(指针) 沿着数组所占据的存储区域向前和向后移动多个或者是一个数组元素 可以在程序的运行过程中根据需要创建的数组 int *v, int *key a, &key add-a &n三、 阅读程序题1. 112. 26893. 3 5 7 9 114. 1 4 7 0 85. 13 12 0 0 03 3 3 3 36 8 11 3 38 9 3 3 33 3 3 3 36 1 1 1 1 1 14 13 1 1 1 1 1 1 1 1 4 6 9 1 1 6 7 1 1 1四、 程序设计题/xt060401.cpp#include void main() int yh11,row
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025缝纫机机器租赁合同
- 兰州市政府2025年度合同管理创新试点合同3篇
- 2025年度酒店客房内墙乳胶漆翻新服务合同3篇
- 2025年度知识产权交易及投资合作协议3篇
- 二零二五年度竞业禁止机械租赁与节能技术合同3篇
- 二零二五年度跨国公司股东合伙人战略合作协议3篇
- 二零二五年度航空航天出资入股协议
- 2025年度生态园林景观设计-特色树苗订购与施工合同
- 二零二五年度生物医药研发项目转让合同3篇
- 二零二五年度房产转让合同中的税务筹划及优惠条款协议3篇
- 05K405 新型散热器选用与安装
- 明亚保险经纪人考试题库答案
- 精心设计“每日一练”探求“轻负高质”练习策略
- 设备维护与故障排除项目设计评估方案
- 针灸推拿学100512练习题库与参考答案
- 常用截面惯性矩与截面系数的计算
- 行车工考试试题
- 小儿头皮静脉输液课件
- 电力电缆高频局放试验报告
- 肺病科主任年度述职汇报
- 2023年福建省晋江市数学七年级第一学期期末学业质量监测试题含解析
评论
0/150
提交评论