第一范文网 - 专业文章范例文档资料分享平台

《c++程序设计》谭浩强课后习题答案及解析 

来源:用户分享 时间:2025/5/28 21:23:29 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

.

第一章 1.5题

#include using namespace std; int main() {

cout<<\ cout<<\ cout<<\ return 0; 1.6题

#include using namespace std; int main() {

int a,b,c; a=10; b=23; c=a+b;

cout<<\ cout<

1.7七题

#include using namespace std; int main() {

int a,b,c;

int f(int x,int y,int z); cin>>a>>b>>c; c=f(a,b,c);

cout<

int f(int x,int y,int z) {

int m;

if (x

return(m);

.

.

}

1.8题

#include using namespace std; int main() {

int a,b,c; cin>>a>>b; c=a+b;

cout<<\ return 0; }

1.9题

#include using namespace std; int main() {

int a,b,c;

int add(int x,int y); cin>>a>>b; c=add(a,b);

cout<<\ return 0; }

int add(int x,int y) {int z; z=x+y; return(z); }

2.3题

#include using namespace std; int main()

{char c1='a',c2='b',c3='c',c4='\\101',c5='\\116'; cout<

cout<<\ return 0; }

2.4题

#include using namespace std; int main()

{char c1='C',c2='+',c3='+';

.

.

cout<<\

cout<<\ return 0; }

2.7题

#include using namespace std; int main() {int i,j,m,n; i=8; j=10;

m=++i+j++;

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

cout<

2.8题

#include using namespace std; int main()

{char c1='C', c2='h', c3='i', c4='n', c5='a'; c1+=4; c2+=4; c3+=4; c4+=4; c5+=4;

cout<<\ return 0; }

3.2题

#include #include using namespace std; int main ( )

{float h,r,l,s,sq,vq,vz;

const float pi=3.1415926; cout<<\ cin>>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;

cout<

.

.

<

cout<<\ cout<<\ cout<<\ cout<<\ cout<<\ return 0; } 3.3题

#include using namespace std; int main () {float c,f;

cout<<\请输入一个华氏温度:\ cin>>f;

c=(5.0/9.0)*(f-32); //注意5和9要用实型表示,否则5/9值为0 cout<<\摄氏温度为:\ return 0; };

3.4题

#include using namespace std; int main ( ) {char c1,c2;

cout<<\请输入两个字符c1,c2:\

c1=getchar(); //将输入的第一个字符赋给c1 c2=getchar(); //将输入的第二个字符赋给c2 cout<<\用putchar函数输出结果为:\ putchar(c1); putchar(c2); cout<

cout<<\用cout语句输出结果为:\ cout<

3.4题另一解

#include using namespace std; int main ( ) {char c1,c2;

cout<<\请输入两个字符c1,c2:\

c1=getchar(); //将输入的第一个字符赋给c1 c2=getchar(); //将输入的第二个字符赋给c2

.

.

cout<<\用putchar函数输出结果为:\ putchar(c1); putchar(44); putchar(c2); cout<

cout<<\用cout语句输出结果为:\ cout<

3.5题

#include using namespace std; int main ( ) {char c1,c2;

int i1,i2; //定义为整型 cout<<\请输入两个整数i1,i2:\ cin>>i1>>i2; c1=i1; c2=i2;

cout<<\按字符输出结果为:\ return 0; }

3.8题

#include using namespace std; int main ( )

{ int a=3,b=4,c=5,x,y;

cout<<(a+b>c && b==c)<b) && !c||1)<

cout<<(!(x=a) && (y=b) && 0)<

include using namespace std; int main ( ) {int a,b,c;

cout<<\ cin>>a>>b>>c; if(a

cout<<\

.

《c++程序设计》谭浩强课后习题答案及解析 .doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c4tr8n37guk79ew80o94h77xpo584e200qvv_1.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top