程序设计技术习题参考答案Word文件下载.docx
《程序设计技术习题参考答案Word文件下载.docx》由会员分享,可在线阅读,更多相关《程序设计技术习题参考答案Word文件下载.docx(92页珍藏版)》请在冰豆网上搜索。
![程序设计技术习题参考答案Word文件下载.docx](https://file1.bdocx.com/fileroot1/2022-11/24/e1dbca0d-372b-4fe1-9e3d-70545a5aea4e/e1dbca0d-372b-4fe1-9e3d-70545a5aea4e1.gif)
,2*PI*r);
圆面积:
%lf\n"
PI*r*r);
圆球表面积:
4*PI*r*r);
圆球体积:
4.0/3*PI*r*r);
圆柱体积:
PI*r*r*h);
}
//xt010402.cpp
{intc;
Inputacharacter:
c=getchar();
%c\t%d\n"
c,c);
//xt010403.cpp
{intx,y,h=30,f=90;
x=(4*h-f)/2;
y=(f-2*h)/2;
鸡:
%d,兔:
%d\n"
x,y);
//xt010404.cpp
math.h>
{doublea,b,c,s,area;
请输入三角形的三条边长(注意三条边长应能够构成三角形):
%lf,%lf,%lf"
a,&
b,&
c);
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
三角形的面积是:
area);
//xt010405.cpp
{doublef,c;
请输入华氏温度:
%lf"
f);
c=5.0/9.0*(f-32);
与华氏温度%.2lf对应的摄氏温度是:
%.2lf\n"
f,c);
//xt010406.cpp
{charc1,c2,c3,c4,c5;
请输入需加密的字符串(5个字符):
c1=getchar();
c2=getchar();
c3=getchar();
c4=getchar();
c5=getchar();
加密后的字符串是:
putchar(c1+5);
putchar(c2+5);
putchar(c3+5);
putchar(c4+5);
putchar(c5+5);
\n"
习题2
一、单项选择题
CBADCCCAAC
①a+b==0&
&
a*b!
=0
②逻辑与
③逻辑或
④continue
⑤(c=getchar())!
='
\n'
⑥%c
答案:
该程序所完成功能的函数关系为:
/*xt020401.cpp*/
{intnum;
****Inputnum:
****\n"
%d"
num);
if(num%3==0&
num%5==0&
num%7==0)
**YES!
**\n"
else
**NO!
/*xt020402.cpp*/
{inth=0;
floatx,y,x0=2,y0=2,d1,d2,d3,d4;
***input:
x,y***\n"
%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;
x=%f,y=%f\n"
h=%d\n"
h);
/*xt020403.cpp*/
voidmain()
{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("
n);
}
/*xt020404.cpp*/
#defineEPS1.0e-6
{
floate=1,t;
longintj=1,n=1;
do
{j=j*n;
t=1.0/j;
e=e+t;
n++;
}while(fabs(t)>
=EPS);
e=%f\n"
e);
/*xt020405.cpp*/
{intnum=1;
{if((num+3)%5==0&
(num-3)%6==0)
break;
num+=1;
}while
(1);
num=%d\n"
num);
/*xt020406.cpp*/
for(num=1;
num<
=99;
num++)
if(num*num%10==num||num*num%100==num)
%4d,%5d"
num,num*num);
/*xt020407.cpp*/
{intn,k=1;
floats=0;
for(n=1;
=10000;
{s=s+1.0/(2.0*n-1)*k;
k=-k;
}
PI=%f\n"
4*s);
/*xt020408.cpp*/
{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)
n10=%d,n5=%d,n2=%d,n1=%d\n"
n10,n5,n2,n1);
}
/*xt020409.cpp*/
{floatsn=100,hn=sn/2;
intn=2;
while(n<
=10)
{sn+=2*hn;
hn=hn/2;
%f,%f\n"
sn,hn);
/*xt020410.cpp*/
{intday,x1,x2=1;
for(day=9;
day>
0;
day--)
{x1=(x2+1)*2;
x2=x1;
Total=%d\n"
x1);
习题3
单项选择题
BBCACDDABB
填空题
①9
②0
③10
④x
⑤一致
⑥n/2
⑦sum+a
⑧sum/n
1.246
2.s=30
3.5945842
4.lanuge
5.816
357
492
6.max=10,row=2,colum=1
//xt030401.cpp
stdlib.h>
time.h>
voidmain(void)
intnum[10],a;
;
srand((unsigned)time(NULL));
请输入一个2位数,试试您是否能中奖:
a);
for(inti=0;
i<
10;
i++)
{num[i]=(rand()+10)%100;
if(a==num[i])
猜中一个数%d下标是%d"
a,i);
-------------------------\n"
for(i=0;
i<
i++)
printf("
%d\t"
num[i]);
//xt030402.cpp
{inta[5]={23,45,60,67,88},x,i,j,yes=0;
for(i=0;
5;
%d,"
a[i]);
\nwhichnumberdoyouwanttodelete?
x);
i++)
if(a[i]==x)
{yes=1;
for(j=i;
j<
j++)a[j]=a[j+1];
if(yes==1)for(i=0;
4;
i++)printf("
elseprintf("
Thenumberyouwantdoesn'
texist"
//xt030403.cpp
#defineSIZE1000
intx,a[SIZE],size,sum=0;
while((size=rand()%1000)>
200);
\nRandomizlistsize(<
1000):
size);
\nAutomakea%dsizeoflist:
for(x=0;
x<
size;
x++)
{a[x]=rand()%1000;
%d\t"
a[x]);
sum+=arr[x];
\nThesumofarrayelementsis%d"
sum);
//xt030404.cpp
#defineSIZE100
intx,a[SIZE],max=0,min=1000,b1,b2;
srand((unsigned)time(NULL));
SIZE;
for(x=0;
{
if(a[x]>
max)max=a[x],b1=x;
if(a[x]<
min)min=a[x],b2=x;
\nThearrayelementsmax=%din%d\nmin=%din%d\n"
max,b1,min,b2);
//xt030405.cpp
#defineKIND5
intx,y,len,total[KIND+1];
inta[]={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(a[0]);
KIND+1;
{total[x]=0;
for(y=1;
y<
y++)
len;
if(a[x]==y)total[y]++;
\nThelistkinded:
x++)printf("
%d"
\nThetotalresult:
for(x=1;
%d-%d,"
x,total[x]);
//xt030406.cpp
#defineN26
intmain(void)
{staticinta[N+1],b[N+1];
inti,j,s,m,p;
%d%d"
s,&
m);
for(i=1;
=N;
i++)a[i]=i;
i=s-1;
j=0;
p=0;
while(p<
N)
{i++;
bh:
if(i>
N)i-=N;
if(a[i]==0){i++;
gotobh;
j++;
if(j%m==0){p++;
b[p]=a[i];
a[i]=0;
%3d"
b[i]);
//xt030407.cpp
void
main()
int
i,j,s=0,ave,v[3];
static
a[5][3]={
{80,75,92},{61,65,71},{59,63,70},{85,87,90},{76,77,85}
};
3;
{
for(j=0;
j++){
s=s+a[j][i];
v[i]=s/5;
s=0;
ave=(v[0]+v[1]+v[2])/3;
math:
%d\nc
languag:
%d\ndbase:
v[0],v[1],v[2]);
totalave:
avel);
//xt030408.cpp
inti,j,a[10][10],b[]={1,2,3,4,5,6,7,8,9,10};
i++)a[0][i]=b[i];
for(i=1;
j++)
if(i>
j)a[i][j]=a[j][i];
elsea[i][j]=a[i-1][j-1];
{for(j=0;
a[i][j]);
//xt030409.cpp
#defineSIZE5000
#defineN7
intx,y,a[N]={0,0,0,0,0,0,0},s;
x=0;
while(x<
SIZE)
{s=rand()%6+1;
if(s>
0&
s<
7)
{a[s]++;
x++;
\nRandomiz1-6list\n"
N;
s=a[x]*0.07;
for(y=0;
s;
x);
\t%d\t%2.1f%%\n"
a[x],(float)a[x]*100/SIZE);
//xt030410.cpp
#defineN20
intmain()
intx,s,tag;
chara[N];
Pleaseinputnumbersandit'
slengthlessthen%d:
N-1);
s=1;
while(s<
{scanf("
%c"
a[s]);
if(a[s]==10)break;
s++;
\nThenumbersis:
tag=0;
s/2;
if(a[x]!
=a[s-x])
{tag=1;
break;
if(tag==0)printf("
\nThenumberispalindrome!
\nThenumberisn'
tpalindrome!
习题4
ABACABCBDD
二、填空题
①主
②main函数
③main函数
④个数
⑤类型
⑥顺序
⑦函数类型
⑧float(floatx,intn)
⑨f(x,n)
⑩x*f(x,n-1)
1.x=5,y=25
2.y=170.0
3.s1=3.14,s2=5.14
4.5002
5.5,3
6.3.00,1.00,0.25
//xt040401.cpp
#include<
voidmain()
{voiddis(intn);
intn;
n);
dis(n);
voiddis(intn)
{intk0,k,sum,i;
k0=1;
{k=k0;
sum=0;
for(i=1;
=n;
{sum=sum+k;
k=k+2;
}
if(sum==n*n*n)
break;
else
k0=k0+2;
for(i=1;
{printf("
%5d"
k0);
k0=k0+2;
//xt040402.cpp
voidmain()
{floath(intn,floatx);
floatx;
%d,%f"
n,&
h(%d,%f)=%f"
n,x,h(n,x));
floath(intn,floatx)
{if(n==0)
return1;
elseif(n==1)
return(2*x);
return(2*x*h(n-1,x)-2*(n-1)*h(n-2,x));
//xt040403.cpp
{intf(intn);
inti;
for(i=2;
=1000;
if(f(i))
printf("
%6d"
i);
intf(intn)
{if(n==n*n%10||n==n*n%100||n==n*n%1000)
return0;
//xt040404.cpp
{longfun(inta,intn);
intk,n;
%d,%d"
k,&