C程序设计综合练习题读程序写结果题Word下载.docx
《C程序设计综合练习题读程序写结果题Word下载.docx》由会员分享,可在线阅读,更多相关《C程序设计综合练习题读程序写结果题Word下载.docx(21页珍藏版)》请在冰豆网上搜索。
:
b<
swap2(&
a,&
b);
swap3(&
swap4(a,b);
3.&
&
iostream.h>
voidprint(intw)
inti;
if(w!
=0)
{
print(w-1);
for(i=1;
i<
=w;
i++)
cout<
w;
}
print(4);
4.
#definesw(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;
a=b=c=0;
for(intk=0;
k<
10;
k++)
cin>
>
x;
switch(x%3)
{
case0:
a+=x;
break;
case1:
b+=x;
case2:
c+=x;
}
c<
6.***
{intj,k;
for(j=5;
j>
0;
j--)
{for(k=j;
k>
k--)
cout<
*"
;
7.
intnNumber;
int*pPointer;
nNumber=15;
pPointer=&
nNumber;
nNumberisequalto:
nNumber<
*pPointer=25;
nNumber<
8.
int*pPointer;
voidSomeFunction()
pPointer=newint;
*pPointer=25;
SomeFunction();
Valueof*pPointer:
*pPointer<
deletepPointer;
9.
voidAddFive(int*Number)
*Number=*Number+5;
intnMyNumber=18;
Myoriginalnumberis"
nMyNumber<
AddFive(&
nMyNumber);
Mynewnumberis"
10.
intArray[3];
Array[0]=10;
Array[1]=20;
Array[2]=30;
int*pArray;
pArray=&
Array[0];
pArraypointstothevalue."
*pArray<
*(pArray+1)<
11.***
inti=4;
i="
i=5;
inti;
i=7;
i;
12.***
voidfun();
fun();
voidfun()
staticinta=1;
inti=5;
a++;
i++;
a="
13.&
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;
intPoint:
countP=0;
voidmain()
{PointA(4,5);
PointA,"
A.GetX()<
A.GetY();
A.GetC();
PointB(A);
PointB,"
B.GetX()<
B.GetY();
B.GetC();
14.***
intaddDefault(intx=1,inty=2);
voidfun(void);
voidmain(void)
intaddDefault(intx=3,inty=4);
addDefault()<
fun();
intaddDefault(intx,inty)
x<
+"
y<
="
returnx+y;
voidfun(void)
15.***
#include<
voidmain()
{intm,n,a=3,b=3,number;
number=237;
m=number/5;
n=number%5;
m="
m<
n="
n<
a+=m;
b*=n;
a="
b="
16.***
{intwidth,height,result1,result2,result3;
height=3;
width=5;
result1=height>
3&
width>
=5;
result2=height>
3||width>
result3=!
(width>
=5);
result1"
result1<
result2"
result2<
result3"
result3<
17.***
{inti=32,j=6;
doubledf;
df=i/j+2.3;
df="
df<
i=df/3;
18.&
#include<
intc[10];
voidadd(intx,inty)
{staticinti=0;
c[i]=x+y;
i++;
{inta[10]={1,2,3,4,5,6,7,8,9,10};
intb[10]={10,9,8,7,6,5,4,3,2,1};
inti=0,k=0;
for(i=0;
add(a[i],b[i]);
c[i]<
19.
{chars[30]="
computer,mouse,key"
s<
while(s[i]!
='
\0'
)
{if(s[i]=='
m'
)//通过数组名和下标引用数组元素
k++;
i++;
k="
k<
20.
{chars[]="
C++program"
char*ps1="
computer"
char*ps2,*ps3=s;
ps2="
mouse"
ps1<
ps2<
ps3<
ps1++;
ps2+=2;
ps3+=4;
s+4<
*s<
*ps1<
*ps2<
*ps3<
ps1=s;
21.如果输入的数据是24和18,则下列程序的输出结果是什么?
***
intfun1(intc,intd)
intr;
r=c%d;
while(r!
=0){
c=d;
d=r;
returnd;
}
intm,n,e,d;
mn="
cin>
m>
n;
e=fun1(m,n);
d=m*n/e;
e<
d<
22.
{inta[3][4]={{1,2,3,4},{3,4,5,6},{5,6,7,8}};
intb[4][3],i,j;
3;
{for(j=0;
4;
a[i][j]<
for(j=0;
b[i][j]=a[j][i];
b[i][j]<
23.
iomanip.h>
{constintm=5;
inta[m][m];
inti,j;
m;
{a[i][0]=1;
a[i][i]=1;
for(j=1;
a[i][j]=a[i-1][j-1]+a[i-1][j];
i++)
{for(intk=0;
30-2*i;
k++)
=i;
setw(5)<
a[i][j];
24.
)
25.
structstudent
{charnum[5];
charname[10];
charsex;
intage;
floatmathscore;
};
{structstudentst[10]={{"
001"
Wangping"
'
f'
19,84},
{"
002"
Zhaomin"
20,64},
003"
Wanghong"
18,54},
004"
Lilei"
19,92},
005"
Liumin"
19,75}};
inti,k=0;
floataverage=0;
average+=st[i].mathscore;
average/=10;
average="
average<
if(st[i].mathscore<
60)
{k++;
st[i].num<
st[i].name<
st[i].sex;
st[i].age<
st[i].mathscore<
}
26.
{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)<
20;
i++)cout<
-"
{for(j=n-1;
j>
=00;
j--)
*(b[i]+j)<
for(i=m-1;
i>
=0;
i--)
27.
{inta[]={12,22,32,42,52,62,72,82,92,102};
inti,m=5;
int*p=a;
*p++<
i--)
p[i]<
28.
{intb[2][4]={12,36,62,14,56,98,74,63};
int(*p)[4]=b;
2;
*(*(p+i)+j)<
{for(j=3;
p[i][j]<
29.
stdlib.h>
{intfunc(inta,intb,charop);
int(*fptr)(inta,intb,charop);
fptr=func;
func(3,5,'
+'
)<
fptr(3,5,'
*'
intfunc(inta,intb,charop)
{
switch(op)
case'
op<
returna+b;
break;
case'
-'
returna-b;
returna*b;
default:
Operatorerror!
return0;
30.
{char*num;
char*name;
intage;
};
{int*ip;
float*fp;
char*cp;
structstudent*stp;
fp=newfloat(32.6);
cp=newchar;
*cp='
A'
ip=newint[10];
for(inti=0;
ip[i]=2*i+2;
stp=newstructstudent;
stp->
num="
12"
name="
Li"
age=18;
*fp<
*cp<
stp->
num<
name="
name<
age="
age<
ip[i]<
deletecp;
deletefp;
delete[]ip;
deletestp;
31.***
classPoint
public:
Point(intxx=0,intyy=0)
{X=xx;
构造函数被调用"
Point(Point&
p);
private:
Point(Point&
p)
X=p.X;
拷贝构造函数被调用"
Pointfun2()
{PointA(1,2);
returnA;
voidfun1(Pointp)
{cout<
p.GetX()<
fun1(A);
B.GetX()<
B=fun2();
32.***
math.h>
public:
Point(intxx=0,intyy=0)
X=xx;
Y=yy;
intGetX(){returnX;
intGetY(){returnY;
Y=p.