c第三章课后习题答案谭浩强.docx
- 文档编号:3862856
- 上传时间:2022-11-26
- 格式:DOCX
- 页数:15
- 大小:16.46KB
c第三章课后习题答案谭浩强.docx
《c第三章课后习题答案谭浩强.docx》由会员分享,可在线阅读,更多相关《c第三章课后习题答案谭浩强.docx(15页珍藏版)》请在冰豆网上搜索。
c第三章课后习题答案谭浩强
题
#include
#include
usingnamespacestd;
intmain()
{floath,r,l,s,sq,vq,vz;
constfloatpi=;
cout<<"pleaseenterr,h:
";
cin>>r>>h;
l=2*pi*r;
s=r*r*pi;
sq=4*pi*r*r;
vq=*pi*r*r*r;
vz=pi*r*r*h;
cout< : fixed)< : right) < (2); cout<<"l="< cout<<"s="< cout<<"sq="< cout<<"vq="< cout<<"vz="< return0; } 题 #include usingnamespacestd; intmain() {floatc,f; cout<<"请输入一个xx: "; cin>>f; c=*(f-32);; cin>>score; } switch(int(score/10)) {case10: case9: grade='A';break; case8: grade='B';break; case7: grade='C';break; case6: grade='D';break; default: grade='E'; } cout<<"scoreis"< return0; } 题 #include usingnamespacestd; intmain() {longintnum; intindiv,ten,hundred,thousand,ten_thousand,place; /*分别代表个位,十位,百位,千位,万位和位数 */ cout<<"enteraninteger(0~99999): "; cin>>num; if(num>9999) place=5; elseif(num>999) place=4; elseif(num>99) place=3; elseif(num>9) place=2; elseplace=1; cout<<"place="< .="< return0; } 题 #include usingnamespacestd; intmain() {floats=0,t=1; intn; for(n=1;n<=20;n++) { t=t*n;.+20! ="< return0; } 题 #include usingnamespacestd; intmain() {inti,j,k,n; cout<<"narcissusnumbersare: "< for(n=100;n<1000;n++) {i=n/100; j=n/10-i*10; k=n%10; if(n==i*i*i+j*j*j+k*k*k) cout< } cout< } 题 #include usingnamespacestd; intmain() {constintm=1000;.,k10 {case1: k1=i;break;< return0; else cout< return0; } intprime(intn) {intflag=1,i; for(i=2;i if(n%i==0) flag=0; return(flag); } 题 #include usingnamespacestd; intmain() {intfac(int); inta,b,c,sum=0; cout<<"entera,b,c: "; cin>>a>>b>>c; sum=sum+fac(a)+fac(b)+fac(c); cout< +"< +"< ="< return0; } intfac(intn) {intf=1; for(inti=1;i<=n;i++) f=f*i; returnf; } 题 #include #include usingnamespacestd; intmain() {doublee(double); doublex,sinh; cout<<"enterx: "; cin>>x; sinh=(e(x)+e(-x))/2; cout<<"sinh("< return0; } doublee(doublex) {returnexp(x);} 题 #include #include usingnamespacestd; intmain() {doublesolut(double,double,double,double); doublea,b,c,d; cout<<"inputa,b,c,d: "; cin>>a>>b>>c>>d; cout<<"x="< return0; } doublesolut(doublea,doubleb,doublec,doubled) {doublex=1,x0,f,f1; do {x0=x; f=((a*x0+b)*x0+c)*x0+d; f1=(3*a*x0+2*b)*x0+c; x=x0-f/f1; } while(fabs(x-x0)>=1e-5); return(x); } 题 #include #include usingnamespacestd; intmain() {voidgodbaha(int); intn; cout<<"inputn: "; cin>>n; godbaha(n); return0; } voidgodbaha(intn) {intprime(int); inta,b; for(a=3;a<=n/2;a=a+2) {if(prime(a)) {b=n-a; if(prime(b)) } intprime(intm) {inti,k=sqrt(m); for(i=2;i<=k;i++) if(m%i==0)break; if(i>k)return1; elsereturn0; } 题 #include usingnamespacestd; intmain() {intx,n; floatp(int,int); cout<<"inputn&x: "; cin>>n>>x; cout<<"n="< cout<<"P"< } floatp(intn,intx) {if(n==0) return (1); elseif(n==1) return(x); else return(((2*n-1)*x*p((n-1),x)-(n-1)*p((n-2),x))/n); } 题 #include usingnamespacestd; intmain() {voidhanoi(intn,charone,chartwo,charthree); intm; cout<<"inputthenumberofdiskes: "; cin>>m; cout<<"Thestepsofmoving"< "< hanoi(m,'A','B','C'); return0; } voidhanoi(intn,charone,chartwo,charthree) < cout<<"continuornot(Y/N)"; cin>>c; if(c=='N'||c=='n') flag=false; } return0; } 题 #include usingnamespacestd; intmain() {intsum_day(int,int); intleap(intyear); intyear,month,day,days=0; cout<<"inputdate(year,month,day): "; cin>>year>>month>>day; cout< days=sum_day(month,day); 数一 */ if(leap(year)&&month>=3) 二 *//*调用函/*调用函数days=days+1; cout<<"isthe"< return0; } intsum_day(intmonth,intday),tran; tran=ch; cout<<"ciphercode: "< j=0; while(j<=()) {if((ch[j]>='A')&&(ch[j]<='Z')) tran[j]=155-ch[j]; elseif((ch[j]>='a')&&(ch[j]<='z')) } cout<<"originaltext: "; cout< return0; } 另一解 tran[j]=219-ch[j]; tran[j]=ch[j]; else j++; #include #include usingnamespacestd; intmain() {intj; stringch="IwillvisitChinanextweek."; cout<<"ciphercode: "< j=0; while(j<=()) {if((ch[j]>='A')&&(ch[j]<='Z')) ch[j]=155-ch[j]; elseif((ch[j]>='a')&&(ch[j]<='z')) ch[j]=219-ch[j]; j++; } cout<<"originaltext: "; cout< return0; } #include #include usingnamespacestd; intmain() {intj; stringch="IwillvisitChinanextweek."; cout<<"ciphercode: "< j=0; while(j<=()) {if((ch[j]>='A')&&(ch[j]<='Z')) ch[j]=155-ch[j]; elseif((ch[j]>='a')&&(ch[j]<='z')) } cout<<"originaltext: "; cout< return0; } 题 ch[j]=219-ch[j]; j++; #include #include usingnamespacestd; intmain() {chars1[80],s2[40]; inti=0,j=0; cout<<"inputstring1: "; cin>>s1; cout<<"inputstring2: "; cin>>s2; while(s1[i]! ='\0') i++; while(s2[j]! ='\0') s1[i++]=s2[j++]; s1[i]='\0'; cout<<"Thenewstringis: "< return0; } 另一解 #include usingnamespacestd; intmain() {chars1[80],s2[40]; cout<<"inputstring1: "; cin>>s1; cout<<"inputstring2: "; cin>>s2; strcat(s1,s2); cout<<"Thenewstringis: "< return0; } 另一解 #include #include usingnamespacestd; intmain() {strings1="week",s2="end"; cout<<"s1="< cout<<"s2="< s1=s1+s2; cout<<"Thenewstringis: "< return0; } 题 #include #include usingnamespacestd; intmain() {constintn=5; inti,j; stringstr[n],temp; cout<<"pleaseinputstrings: "< for(i=0;i cin>>str[i]; for(i=0;i for(j=0;j if(str[j]>str[j+1]) {temp=str[j];str[j]=str[j+1];str[j+1]=temp;} cout< "< for(i=0;i } 题 #include #include usingnamespacestd; intmain() {constintn=5; stringstr; for(inti=0;i {cout<<"pleaseinputstring: "; cin>>str; } 题 #include usingnamespacestd; intmain() {constn=10; inti; chara[n],temp; cout<<"pleaseinputastring: "; for(i=0;i cin>>a[i]; for(i=0;i {temp=a[i];a[i]=a[n-i-1];a[n-i-1]=temp;}
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 第三 课后 习题 答案 谭浩强