文档下载 文档下载导航
设为首页 | 加入收藏
搜索 请输入内容:  
 导航当前位置: 文档下载 > 所有分类 > 高等教育 > 理学 > C++课后习题答案_谭浩强
侵权投诉

C++课后习题答案_谭浩强

第一章

5:输出结果为: ThisisaC++program

6: 输出结果为: a+b=33 7: 求最小值

#include <iostream> 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<<c<<endl; return 0; }

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

int m;

if (x<y) m=x; else m=y; if (z<m) m=z;

return(m); }

8:求加法

#include <iostream> using namespace std; int main() {

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

cout<<"a+b="<<a+b<<endl; return 0; }

9: 求加法

#include <iostream> using namespace std; int main()

{int add(int x,int y); int a,b,c; cin>>a>>b; cout<<"a+b="<<c<<endl; return 0; }

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

10: 从小到大排序 #include <iostream> using namespace std; int main()

{void sort(int x,int y,int z); int x,y,z;

cin>>x>>y>>z; sort(x,y,z); return 0; }

void sort(int x, int y, int z) {

int temp;

if (x>y) {temp=x;x=y;y=temp;} //{ }内3个语句的作用是将x和y的值互换) if (z<x) cout<<z<<','<<x<<','<<y<<endl; else if (z<y) cout<<x<<','<<z<<','<<y<<endl; else

cout<<x<<','<<y<<','<<z<<endl; } 11:

#include <iostream> using namespace std; int main()

{int max(int a,int b,int c=0); int a,b,c;

cin>>a>>b>>c;

cout<<"max(a,b,c)="<<max(a,b,c)<<endl; cout<<"max(a,b)="<<max(a,b)<<endl; return 0; }

int max(int a,int b,int c) {if(b>a) a=b; if(c>a) a=c; return a;

第1页

你可能喜欢

  • 天然药物化学试卷16答案
  • 谭浩强c语言答案
  • 西方经济学高鸿业课后习题答案
  • 谭浩强c语言习题答案
  • 管理学原理阶段测试题答案
  • 面向对象程序设计课后习题答案

热门文档

相关文档

站点地图 | 文档上传 | 侵权投诉 | 手机版
本站所有资源均来自互联网,本站只负责收集和整理,均不承担任何法律责任,如有侵权等其它行为请联系我们.
文档下载 Copyright 2013 doc.guandang.net All Rights Reserved.  -  email