您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > 程序设计技术习题参考答案
《程序设计技术》(第三版)习题参考答案习题1一、单项选择题DADDDBCCD(注:第7小题无正确选项,正确答案为-12)二、填空题①主②main③x=x*(x+b)④普通、格式、分隔和转义⑤指定输出数据格式⑥voidmain()⑦howareyou!三、阅读程序题1.9,11,9,102.2,-1,-13.aabbccabc4.2,25.575767.5864000,-789.12402367.5864000,-7.89e+00267,86,-789.12,67.5864000,-789.124023,67.5864000,-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#includestdio.h#definePI3.1415926voidmain(){doubler,h;printf(请输入半径r和高h:);scanf(%lf,%lf,&r,&h);printf(圆半径:%lf\n,2*PI*r);printf(圆面积:%lf\n,PI*r*r);printf(圆球表面积:%lf\n,4*PI*r*r);printf(圆球体积:%lf\n,4.0/3*PI*r*r);printf(圆柱体积:%lf\n,PI*r*r*h);}//xt010402.cpp#includestdio.hvoidmain(){intc;printf(Inputacharacter:);c=getchar();printf(%c\t%d\n,c,c);}//xt010403.cpp#includestdio.hvoidmain(){intx,y,h=30,f=90;x=(4*h-f)/2;y=(f-2*h)/2;printf(鸡:%d,兔:%d\n,x,y);}//xt010404.cpp#includestdio.h#includemath.hvoidmain(){doublea,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(三角形的面积是:%lf\n,area);}//xt010405.cpp#includestdio.hvoidmain(){doublef,c;printf(请输入华氏温度:);scanf(%lf,&f);c=5.0/9.0*(f-32);printf(与华氏温度%.2lf对应的摄氏温度是:%.2lf\n,f,c);}//xt010406.cpp#includestdio.hvoidmain(){charc1,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一、单项选择题CBADCCCAAC二、填空题①a+b==0&&a*b!=0②逻辑与③逻辑或④continue⑤(c=getchar())!='\n'⑥%c三、阅读程序题答案:答案:该程序所完成功能的函数关系为:)0(1)0(0)0(1xxxxsign答案:答案:答案:答案:四、程序设计题/*xt020401.cpp*/#includestdio.hvoidmain(){intnum;printf(****Inputnum:****\n);scanf(%d,&num);if(num%3==0&&num%5==0&&num%7==0)printf(**YES!**\n);elseprintf(**NO!**\n);}/*xt020402.cpp*/#includestdio.hvoidmain(){inth=0;floatx,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=%f\n,x,y);printf(h=%d\n,h);}/*xt020403.cpp*/#includestdio.hvoidmain(){inti,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(%d\n,n);}}/*xt020404.cpp*/#includestdio.h#includemath.h#defineEPS1.0e-6voidmain(){floate=1,t;longintj=1,n=1;do{j=j*n;t=1.0/j;e=e+t;n++;}while(fabs(t)=EPS);printf(e=%f\n,e);}/*xt020405.cpp*/#includestdio.hvoidmain(){intnum=1;do{if((num+3)%5==0&&(num-3)%6==0)break;num+=1;}while(1);printf(num=%d\n,num);}/*xt020406.cpp*/#includestdio.hvoidmain(){intnum;for(num=1;num=99;num++)if(num*num%10==num||num*num%100==num)printf(%4d,%5d,num,num*num);printf(\n);}/*xt020407.cpp*/#includestdio.hvoidmain(){intn,k=1;floats=0;for(n=1;n=10000;n++){s=s+1.0/(2.0*n-1)*k;k=-k;}printf(PI=%f\n,4*s);}/*xt020408.cpp*/#includestdio.hvoidmain(){intn10,n5,n2,n1;for(n10=1;n10=9;n10++)for(n5=1;n5=17;n5++)for(n2=1;n2=37;n2++){n1=40-n10-n5-n2;if(n1=1&&n10*10+n5*5+n2*2+n1==100)printf(n10=%d,n5=%d,n2=%d,n1=%d\n,n10,n5,n2,n1);}}/*xt020409.cpp*/#includestdio.hvoidmain(){floatsn=100,hn=sn/2;intn=2;while(n=10){sn+=2*hn;hn=hn/2;n++;}printf(%f,%f\n,sn,hn);}/*xt020410.cpp*/#includestdio.hvoidmain(){intday,x1,x2=1;for(day=9;day0;day--){x1=(x2+1)*2;x2=x1;}printf(Total=%d\n,x1);}习题3单项选择题BBCACDDABB填空题①9②0③10④x⑤一致⑥n/2⑦sum+a⑧sum/n三、阅读程序题1.2462.s=303.59458424.lanuge5.8163574926.max=10,row=2,colum=1四、程序设计题//xt030401.cpp#includestdio.h#includestdlib.h#includetime.hvoidmain(void){intnum[10],a;;srand((unsigned)time(NULL));printf(请输入一个2位数,试试您是否能中奖:);scanf(%d,&a);for(inti=0;i10;i++){num[i]=(rand()+10)%100;if(a==num[i])printf(猜中一个数%d下标是%d,a,i);}}printf(-------------------------\n);for(i=0;i10;i++)printf(%d\t,num[i]);}//xt030402.cpp#includestdio.h#includestdlib.h#includetime.hvoidmain(void){inta[5]={23,45,60,67,88},x,i,j,yes=0;for(i=0;i5;i++)printf(%d,,a[i]);printf(\nwhichnumberdoyouwanttodelete?\n);scanf(%d,&x);for(i=0;i5;i++)if(a[i]==x){yes=1;for(j=i;j5;j++)a[j]=a[j+1];}if(yes==1)for(i=0;i4;i++)printf(%d,,a[i]);elseprintf(Thenumberyouwantdoesn'texist);}//xt030403.cpp#includestdio.h#includestdlib.h#includetime.h#defineSIZE1000voidmain(){intx,a[SIZE],size,sum=0;srand((unsigned)time(NULL));while((size=rand()%1000)200);printf(\nRandomizlistsize(1000):%d,size);printf(\nAutomakea%dsizeoflist:\n,size);for(x=0;xsize;x++){a[x]=rand()%1000;printf(%d\t,a[x]);sum+=arr[x];}printf(\nThesumofarrayelementsis%d,sum);}//xt030404.cpp#includestdio.h#includestdlib.h#includetime.h#defineSIZE100voidmain(){intx,a[SIZE],max=0,min=1000,b1,b2;srand((unsigned)time(NULL));printf(\nAutomakea%dsizeoflist:\n,size);for(x=0;xSIZE;x++){a[x]=rand()%1000;printf(%d\t,a[x]);}for(x=0;xSIZE;x++){if(a[x]max)max=a[x],b1=x;if(a[x]min)min=a[x],b2=x;}printf(\nThearrayelementsmax=%din%d\nmin=%din%d\n,max,b1,min,b2);}//xt030405.cpp#includestdio.h#defineSIZ
本文标题:程序设计技术习题参考答案
链接地址:https://www.777doc.com/doc-2238117 .html