1、程序设计技术习题参考答案程序设计技术(第三版)习题参考答案习题1一、单项选择题 DADDD B 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, -
2、789.1240236.758640e+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(%
3、lf,%lf,&r,&h); printf(圆半径: %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=3
4、0,f=90; x=(4*h-f)/2; y=(f-2*h)/2; 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
5、 f,c; printf(请输入华氏温度:); scanf(%lf,&f); c=5.0/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); putc
6、har(c3+5); putchar(c4+5); putchar(c5+5); printf(n);习题2一、 单项选择题 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) pr
7、intf(* YES ! *n); else printf(* NO ! *n);/* xt020402.cpp */#include 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)+(
8、y+y0)*(y+y0); if(d1=1|d2=1|d3=1|d4=1) h=15; printf(x=%f, y=%fn,x,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=
9、1,t; long int j=1,n=1; do j=j*n; t=1.0/j; e=e+t; n+; while ( fabs(t) = 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*nu
10、m%10=num|num*num%100=num) printf(%4d,%5d,num,num*num); printf(n);/* xt020407.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;
11、n2=1&n10*10+n5*5+n2*2+n1=100) printf(n10=%d,n5=%d,n2=%d,n1=%dn,n10,n5,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;
12、 printf(Total=%dn,x1);习题3单项选择题BBCAC DDABB填空题 9 0 10 x 一致 n/2 sum+a sum/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
13、,&a); for(int i=0;i10;i+) numi = (rand()+10)%100; if(a = numi) printf(猜中一个数 %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 de
14、lete?n); scanf(%d,&x); for(i=0;i5;i+) if(ai=x) yes=1; for(j=i;j5;j+) aj=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
15、()%1000)200); printf(nRandomiz list size(1000):%d,size); printf(nAuto 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=
16、1000,b1,b2;srand(unsigned)time(NULL); printf(nAuto make a %d size of list: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#defin
17、e KIND 5void main() int x,y,len,totalKIND+1; int a=1,1,1,1,2,2,2,3,5,5,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 resul
18、t: ); for(x=1;xKIND+1;x+) printf( %d-%d, ,x,totalx);/xt030406.cpp#define 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);
19、 printf(n);/xt030407.cpp#include voidmain()inti,j,s=0,ave,v3;staticinta53=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
20、,j,a1010, b=1,2,3,4,5,6,7,8,9,10; for(i=0;i10;i+) a0i=bi; for(i=1;i10;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(NU
21、LL); x=0; while(x0&s7) as+; x+; printf(nRandomiz 1-6 list n); for(x=1;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
22、(sN) scanf(%c,&as); if(as=10)break; s+; printf(nThe numbers is :n); for(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
23、(float x,int n) f(x,n) x*f(x,n-1) 三、阅读程序题1 x=5,y=252. y=170.03. s1=3.14,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; do k=k0; sum=0; for(i=1;i=n;i+) sum=sum+k; k=k+2; if(sum=n*n*
24、n) break; else k0=k0+2; while(1); for(i=1;i=n;i+) printf(%5d,k0); k0=k0+2; /xt040402.cpp#include 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); else return(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);int f(int n) if(n=n*n%10|n=n*n%100|n=n*n%1000) return 1; else return 0;/xt040404.cpp#include void main( ) long fun(int a,int n); int k,n; scanf(%d,%d,&k,&n);
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1