C++课后题答案Word文档下载推荐.docx

上传人:b****4 文档编号:8158567 上传时间:2023-05-10 格式:DOCX 页数:100 大小:37.07KB
下载 相关 举报
C++课后题答案Word文档下载推荐.docx_第1页
第1页 / 共100页
C++课后题答案Word文档下载推荐.docx_第2页
第2页 / 共100页
C++课后题答案Word文档下载推荐.docx_第3页
第3页 / 共100页
C++课后题答案Word文档下载推荐.docx_第4页
第4页 / 共100页
C++课后题答案Word文档下载推荐.docx_第5页
第5页 / 共100页
C++课后题答案Word文档下载推荐.docx_第6页
第6页 / 共100页
C++课后题答案Word文档下载推荐.docx_第7页
第7页 / 共100页
C++课后题答案Word文档下载推荐.docx_第8页
第8页 / 共100页
C++课后题答案Word文档下载推荐.docx_第9页
第9页 / 共100页
C++课后题答案Word文档下载推荐.docx_第10页
第10页 / 共100页
C++课后题答案Word文档下载推荐.docx_第11页
第11页 / 共100页
C++课后题答案Word文档下载推荐.docx_第12页
第12页 / 共100页
C++课后题答案Word文档下载推荐.docx_第13页
第13页 / 共100页
C++课后题答案Word文档下载推荐.docx_第14页
第14页 / 共100页
C++课后题答案Word文档下载推荐.docx_第15页
第15页 / 共100页
C++课后题答案Word文档下载推荐.docx_第16页
第16页 / 共100页
C++课后题答案Word文档下载推荐.docx_第17页
第17页 / 共100页
C++课后题答案Word文档下载推荐.docx_第18页
第18页 / 共100页
C++课后题答案Word文档下载推荐.docx_第19页
第19页 / 共100页
C++课后题答案Word文档下载推荐.docx_第20页
第20页 / 共100页
亲,该文档总共100页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

C++课后题答案Word文档下载推荐.docx

《C++课后题答案Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《C++课后题答案Word文档下载推荐.docx(100页珍藏版)》请在冰点文库上搜索。

C++课后题答案Word文档下载推荐.docx

a'

c2='

b'

c3='

c'

c4='

\101'

c5='

\116'

c1<

c2<

c3<

'

\n'

\t\b"

c4<

\t'

c5<

2-4

C'

+'

Isay:

\"

\"

\t\t"

Hesays:

C++isveryinteresting!

'

2-7

{inti,j,m,n;

i=8;

j=10;

m=++i+j++;

n=(++i)+(++j)+m;

i<

j<

m<

n<

2-8

{charc1='

c2='

h'

c3='

i'

c4='

n'

c5='

c1+=4;

c2+=4;

c3+=4;

c4+=4;

c5+=4;

passwordis:

3-2

iomanip>

intmain()

{floath,r,l,s,sq,vq,vz;

constfloatpi=3.1415926;

pleaseenterr,h:

r>

h;

l=2*pi*r;

s=r*r*pi;

sq=4*pi*r*r;

vq=3.0/4.0*pi*r*r*r;

vz=pi*r*r*h;

setiosflags(ios:

:

fixed)<

right)

<

setprecision

(2);

l="

setw(10)<

l<

s="

s<

sq="

sq<

vq="

vq<

vz="

vz<

}

3-3

intmain()

{floatc,f;

请输入一个华氏温度:

f;

c=(5.0/9.0)*(f-32);

//注意5和9要用实型表示,否则5/9值为0

摄氏温度为:

};

3-4-1

{charc1,c2;

请输入两个字符c1,c2:

c1=getchar();

//将输入的第一个字符赋给c1

c2=getchar();

//将输入的第二个字符赋给c2

用putchar函数输出结果为:

putchar(c1);

putchar(44);

putchar(c2);

用cout语句输出结果为:

"

3-4

3-5

inti1,i2;

//定义为整型

请输入两个整数i1,i2:

i1>

i2;

c1=i1;

c2=i2;

按字符输出结果为:

"

3-8

{inta=3,b=4,c=5,x,y;

(a+b>

c&

&

b==c)<

(a||b+c&

b-c)<

(!

(a>

b)&

!

c||1)<

(x=a)&

(y=b)&

0)<

(a+b)+c-1&

b+c/2)<

3-9-1

{inta,b,c;

pleaseenterthreeintegernumbers:

if(a<

b)

if(b<

c)

max="

else

elseif(a<

a;

}

3-9-2

{inta,b,c,temp,max;

temp=(a>

b)?

a:

/*将a和b中的大者存入temp中*/

max=(temp>

c)?

temp:

/*将a和b中的大者与c比较,最大者存入max*/

max<

3-10

{intx,y;

enterx:

x;

1)

{y=x;

x="

x<

y=x="

y;

elseif(x<

10)//1≤x<10

{y=2*x-1;

y=2*x-1="

else//x≥10

{y=3*x-11;

y=3*x-11="

3-11

{floatscore;

chargrade;

pleaseenterscoreofstudent:

score;

while(score>

100||score<

0)

{cout<

dataerror,enterdataagain."

switch(int(score/10))

{case10:

case9:

grade='

A'

break;

case8:

B'

case7:

case6:

D'

default:

grade='

E'

scoreis"

score<

gradeis"

grade<

3-12

{longintnum;

intindiv,ten,hundred,thousand,ten_thousand,place;

/*分别代表个位,十位,百位,千位,万位和位数*/

enteraninteger(0~99999):

num;

if(num>

9999)

place=5;

elseif(num>

999)

place=4;

99)

place=3;

9)

place=2;

elseplace=1;

place="

place<

//计算各位数字

ten_thousand=num/10000;

thousand=(int)(num-ten_thousand*10000)/1000;

hundred=(int)(num-ten_thousand*10000-thousand*1000)/100;

ten=(int)(num-ten_thousand*10000-thousand*1000-hundred*100)/10;

indiv=(int)(num-ten_thousand*10000-thousand*1000-hundred*100-ten*10);

originalorder:

switch(place)

{case5:

cout<

ten_thousand<

thousand<

hundred<

ten<

indiv<

reverseorder:

break;

case4:

case3:

case2:

case1:

3-13-1

{longi;

//i为利润

floatbonus,bon1,bon2,bon4,bon6,bon10;

bon1=100000*0.1;

//利润为10万元时的奖金

bon2=bon1+100000*0.075;

//利润为20万元时的奖金

bon4=bon2+100000*0.05;

//利润为40万元时的奖金

bon6=bon4+100000*0.03;

//利润为60万元时的奖金

bon10=bon6+400000*0.015;

//利润为100万元时的奖金

enteri:

i;

if(i<

=100000)

bonus=i*0.1;

//利润在10万元以内按10%提成奖金

elseif(i<

=200000)

bonus=bon1+(i-100000)*0.075;

//利润在10万元至20万时的奖金

=400000)

bonus=bon2+(i-200000)*0.05;

//利润在20万元至40万时的奖金

=600000)

bonus=bon4+(i-400000)*0.03;

//利润在40万元至60万时的奖金

=1000000)

bonus=bon6+(i-600000)*0.015;

//利润在60万元至100万时的奖金

bonus=bon10+(i-1000000)*0.01;

//利润在100万元以上时的奖金

bonus="

bonus<

3-13-2

{longi;

intc;

bon4=bon2+200000*0.05;

bon6=bon4+200000*0.03;

c=i/100000;

if(c>

10)c=10;

switch(c)

{case0:

case3:

case4:

case5:

case10:

3-14

{intt,a,b,c,d;

enterfournumbers:

c>

d;

a="

a<

b="

b<

c="

d="

d<

if(a>

{t=a;

a=b;

b=t;

a=c;

c=t;

d)

a=d;

d=t;

if(b>

{t=b;

b=c;

b=d;

{t=c;

c=d;

thesortedsequence:

"

3-15

{intp,r,n,m,temp;

pleaseentertwopositiveintegernumbersn,m:

n>

m;

if(n<

m)

{temp=n;

n=m;

m=temp;

//把大数放在n中,小数放在m中

p=n*m;

//先将n和m的乘积保存在p中,以便求最小公倍数时用

while(m!

=0)//求n和m的最大公约数

{r=n%m;

m=r;

HCF="

LCD="

p/n<

//p是原来两个整数的乘积

3-16

{charc;

intletters=0,space=0,digit=0,other=0;

enteroneline:

while((c=getchar())!

='

{if(c>

&

c<

z'

||c>

Z'

letters++;

elseif(c=='

space++;

elseif(c>

0'

9'

digit++;

other++;

letter:

letters<

space:

space<

digit:

digit<

other:

other<

}

3-17

{inta,n,i=1,sn=0,tn=0;

a,n=:

n;

while(i<

=n)

{tn=tn+a;

//赋值后的tn为i个a组成数的值

sn=sn+tn;

//赋值后的sn为多项式前i项之和

a=a*10;

++i;

a+aa+aaa+...="

sn<

3-18

{floats=0,t=1;

intn;

for(n=1;

=20;

n++)

{

t=t*n;

//求n!

s=s+t;

//将各项累加

1!

+2!

+...+20!

="

3-19

{inti,j,k,n;

narcissusnumbersare:

for(n=100;

1000;

{i=n/100;

j=n/10-i*10;

k=n%10;

if(n==i*i*i+j*j*j+k*k*k)

"

3-20-1

intmain()

{constintm=1000;

//定义寻找范围

intk1,k2,k3,k4,k5,k6,k7,k8,k9,k10;

inti,a,n,s;

for(a=2;

=m;

a++)//a是2~1000之间的整数,检查它是否为完数

{n=0;

//n用来累计a的因子的个数

s=a;

//s用来存放尚未求出的因子之和,开始时等于a

for(i=1;

i++)//检查i是否为a的因子

if(a%i==0)//如果i是a的因子

{n++;

//n加1,表示新找到一个因子

s=s-i;

//s减去已找到的因子,s的

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2