第一章
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;
c++程序设计谭浩强课后习题答案(完整版)_工学_高等教育_教育专区。第一章 1....a:b; 存入 temp 中 */ max=(temp>c)?temp:c; /* 将 a 和 b 中的...
《c++程序设计》谭浩强课后习题答案_工学_高等教育_教育专区。c++程序设计谭...(c1); putchar(44); putchar(c2); cout<<endl; cout<<"用cout语句输出...
《c++程序设计》谭浩强课后习题答案_理学_高等教育_教育专区。第一章 1.5 ...{ int a,b,c; a=10; b=23; c=a+b; cout<<"a+b="; cout<<c; ...
c++程序设计谭浩强课后习题答案(完整版)_工学_高等教育_教育专区。第一章 1....a:b; 存入 temp 中 */ max=(temp>c)?temp:c; /* 将 a 和 b 中的...
c++面向对象程序设计课后习题答案(谭浩强版)_教育学_高等教育_教育专区。c++...{int c; c=x+y; return(c); } 10: #include <iostream> using ...
C++第三章课后习题答案 谭浩强_理学_高等教育_教育专区。C++第三章课后习题答案... cout<<c1<<","<<c2<<endl; return 0; } 3.5 题 #include <...
1.6 题 #include <iostream> using namespace std; int main() { int a,b,c; a=10; b=23; c=a+b; cout<<"a+b="; cout<<c; cout<<endl; ...
c++面向对象程序设计课后习题答案(谭浩强版)_理学_高等教育_教育专区。第一章...{int c; c=x+y; return(c); } 10: #include <iostream> using ...
C程序设计(第四版)(谭浩强... 83页 5财富值喜欢此文档的还喜欢... C++面向对象程序设计(谭浩强)课后习题答案C++面向对象程序设计(谭浩强)课后习题...
热门文档