C程序设计综合练习题读程序写结果题Word文档格式.docx
- 文档编号:16906076
- 上传时间:2022-11-27
- 格式:DOCX
- 页数:20
- 大小:19.72KB
C程序设计综合练习题读程序写结果题Word文档格式.docx
《C程序设计综合练习题读程序写结果题Word文档格式.docx》由会员分享,可在线阅读,更多相关《C程序设计综合练习题读程序写结果题Word文档格式.docx(20页珍藏版)》请在冰豆网上搜索。
z/<
swap4(a,b);
z,:
}
3・&
&
ftinclude<
voidprint(intw)
inti;
if(w!
=0)
print(w-1);
for(i=l;
i<
=w;
i++)
cout«
w;
cout<
print(4);
4.
ttdefinesw(x,y){x二y;
y二x;
x二y;
inta=10,b=01;
sw(a,b);
,,>
,?
b;
5.假定输入10个整数:
32,64,53,87,54,32,98,56,98,83。
下列程序的输出结果是什么?
&
voidmain()
inta,b,c,x;
for(int20;
k<
10;
k++)
cin>
>
x;
switch(x%3)
case0:
a+=x;
break;
casel:
b+=x;
case2:
c+=x;
,//,<
,/,,<
c<
6.***
iostream・h>
{intj,k;
for(j=5;
j>
0;
j--)
{for(k=j:
k>
k—)
cout〈C'
x"
;
7.
tiinclude<
intnNumber;
int^pPointer;
nNumber=15:
pPointer二&
nNumber;
,,nNumberisequaltonNumber<
^pPointer二25:
cout〈〈"
nNumberisequalto:
z,<
nNumber<
int*pPointer;
voidSomeFunction()
pPointer二newint:
*pPointer二25;
SomeFunction();
z,Valueof*pPointer:
"
«
*pPointer<
deletepPointer;
9.
voidAddFive(int*Number)
*Number二^Number+5:
intnMyNumber二18;
zzMyoriginalnumberis,,«
nMyNumber«
AddFive(SnMyNumber);
/zMynewnumberisz,<
nMyNumber<
voidmain()
intArray[3J;
Array[OZ二10;
Array[1J二20;
Array[2]二30;
int*pArray;
pArray二&
Array[0]:
,,pArraypointstothevalue・"
cout<
X*pArray<
*(pArtay+l)<
11.***
#include<
inti二4;
,,i=,/<
i二5;
i=7;
,zi=,,«
i«
COUt«
,,i=,/«
i;
12.***
voidfun();
fun();
voidfun()
staticinta=l;
inti=5;
a++;
i卄;
,,i=,,<
/,,a=,,«
a«
9/30
13.&
ttinclude<
classPoint
{public:
Point(intxx=0,intyy二0){X二xx;
Y二yy;
countP++;
Point(Point&
p);
intGetX(){returnX;
intGetY(){returnY;
voidGetC(){cout〈<
"
Objectid=,,<
countP<
}private:
intX,Y;
staticintcountP;
};
Point:
:
Point(Point&
p)
{X二p.x;
Y二p.Y;
countP++;
intPoint:
countP=0:
{PointA(4,5);
APointA,,,«
A.GetX()«
〃,〃〈<
A.GetY();
A.GetC();
PointB(A);
,,PointB,〃<
〈B.GetX()〈<
〃,〃《B.GetY();
B.GetC();
14***
intaddDefaux=l,inty二2);
voidfun(void);
voidmain(void)
intaddDefault(intx=3,inty二4);
addDefault()«
intaddDefault(intx,inty)
x<
,,+,,<
y<
//=:
//;
returnx+y;
voidfun(void)
addDefault()<
15.
***
fintm,n,a=3,b=3,number;
number二237;
m=number/5;
n=number%5;
,/m=/,«
m<
,/n=/,«
n<
a+=m;
b*二n;
,/a=,,«
/zb=,,«
b<
{intwidth,height,resultl,result2,result3;
height二3;
width二5;
resultl二height>
3&
width>
=5:
result2二height>
3width>
=5;
result3=!
(width>
=5);
,,resultl,,<
resultl<
/,result2//<
resuIt2<
,,result3,,<
result3<
17.***
{inti=32,j=6;
doubledf;
df二i/j+2.3;
,,df=,/<
df<
i=df/3;
z/i=,,<
18.&
intc[10];
voidadd(intx,inty)
{staticinti=0;
c[i]二x+y;
{inta[10]={l,2,3,4,5,6,7,8,9,10};
intb[10]={10,9,8,7,6,5,4,3,2,1};
inti二0,20;
for(i=0;
add(a[i],b[i]);
c[i]<
z,“;
19.
ftinclude<
{chars[30]二"
computer,mouse,key"
int1=0,k=0;
s<
while(s[i]!
二’\0‘)
{辻(s[i]二二'
mJ〃通过数组名和下标引用数组元素
k卄;
,,k=,z<
k«
20.
{chars[]二〃C++program"
char*psl二"
computer"
char*ps2,*ps3二s;
ps2二"
mouse"
psl«
ps2<
,/"
〈〈ps3«
psl++;
ps2+=2;
ps3+=4;
s+4<
psl<
,//z«
/,,,«
ps3<
*s〈<
,,«
*psl<
*ps2〈<
〈*ps3<
psi二s;
21.如果输入的数据是24和18,则下列程序的输出结果是什么?
intfunl(intc,intd)
intr;
r=c%d;
while(r!
=O){
c二d;
d二r;
returnd;
intm,n,e,d;
z,mn二〃;
cin>
m>
n;
e二funl(m,n);
d二m*n/e;
e<
d<
{inta[3][4]={{l,2,3,4},{3,4,5,6},{5,6,7,8}};
intb[4][3],i,j;
3;
{for(j=0;
4;
a[i][j]<
z,”;
for(j=0;
b[i][j]二a[j][i];
b[i][j]<
z,”;
23.
★include<
iomanip.h>
{constintm=5;
inta[m][m];
inti,j;
m;
for(j=l;
i;
a[i][j]=a[i-l][j-l]+a[i-l][j];
{for(intk=0;
k<
30-2*i;
k++)
cou“;
=i;
setw(5)〈<
a[i][j];
24.
nclude<
inti=0,k=0;
s«
while(sLi]!
二'
\0‘)
{if(s[i]==,m,)
k++;
i++;
,,k=,,<
25.
Sinclude<
iomanip・h>
structstudent
{charnum[5];
charname[10];
charsex;
intage:
floatmathscore;
{structstudentst[10]二{{"
001"
"
Wangping"
'
f'
19,84},
{"
002"
Zhaomin"
m,20,64},
003"
^Wanghong^,1f‘,1&
54},{'
OOr/Xilei'
/m
005"
Liumin"
'
iinti,k=0:
floataverage二0;
average*二st[i]・mathscore;
average/^lO;
z/average=,z<
average<
for(i=0;
if(st[i]・mathsco:
re〈60)
{k++;
stLi]・num«
〃
〈<
st[i].sex;
/,
st[i]・mathscore«
19,92},
\19,75}};
〃<
〈st[i]・name<
X"
st[i]・age«
,z
{intb[3][4]={23,38,16,12,56,89,66,34,58,12,90,100};
inti,j,m=3,n=4:
{for(j=0;
*(*(b+i)+j)<
*cout<
for(i=0;
i<
20;
i++)cout<
,,-,/;
{for(j=n-l:
=00:
j—)
*(b[i]+j)«
z“;
cout〈〈endl;
,,-,/:
for(i=m-l;
i>
=0;
i--)
{inta[]={12,22,32,42,52,62,72,82,92,102};
inti,m二5;
int*p=a;
*p++«
”;
=0:
p[i]<
z,”;
#include<
{intb[2][4]={12,36,62,14,56,98,74,63};
int(*p)[4]=b;
2;
*(*(p+i)+j)<
,z"
i-+)cout<
〃-"
{for(j=3;
p[i][j]«
,z“;
29.
stdlib.h>
{intfunc(inta,intb,charop);
int(*fptr)(inta,intb,charop);
fptr二func;
func(3,5J+'
)«
fptr(3,5,'
*'
)<
intfunc(inta,intb,charop)
switch(op)
case+:
op«
,,=zz;
returna+b;
case'
-'
,,:
=/z;
returna~b;
cout〈〈a<
〈op〈〈b<
〈〃="
returna*b;
break;
default:
Operatorerror!
,z«
return0:
30.
{char*num;
char*name;
intage;
{int*ip;
float*fp;
char*cp;
structstudent*stp;
fp二newfloat(32.6);
cp二newchar;
ip二newint[10];
for(inti=0;
ip[i]二2*i+2;
stp二newstructstudent;
stp-〉num二"
12"
stp->
name二〃Li〃;
age二18;
*fp<
,/,z<
cou〈"
num="
num«
name二"
《stp-〉name〈<
age二"
stp-〉age«
ip[i]«
,z“;
deletecp;
deletefp;
delete[]ip;
deletestp;
31.***
public:
Point(intxx=0,intyy=0)
{X二xx;
构造函数被调用,,<
Point(Point&
p);
private:
};
Point(Point&
p)
X二p.X;
,z拷贝构造函数被调用/z«
Pointfun2()
{PointA(1,2);
returnA;
voidfunl(Pointp)
{cout<
p.GetX()<
{PointA(l,2);
funl(A);
B.GetX()«
B二fun2();
32.***
math・h>
Point(intxx=0,intyy二0)
X二XX;
Y二yy;
,/构造函数被调用"
intGetX(){returnX;
intGetY(){returnY:
intX,Y;
};
X二p.x;
Y=p.Y;
/,Point拷贝构造函数调用,,<
classDistance
Distance(Pointxpl,Pointxp2):
doubleGetDis(){returndist;
Pointpl,p2;
doubledist;
Distance:
Distance(Pointxpl,Pointxp2)
pl(xpl),p2(xp2)
z,Distance构造函数调用,z<
doublex=double(pl.GetX()-p2.GetX());
doubley=double(pl.GetY()-p2.GetY());
dist=sqrt(x*x+y*y);
Pointmypl(1,1),myp2(4,5);
Distancemyd(mypl,myp2);
z,Thedistanceis:
〃;
cout〈〈myd・Ge
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 程序设计 综合 练习题 程序 结果