第一章C++习题
来源:互联网 发布:node express作用 编辑:程序博客网 时间:2024/05/29 10:38
第七题
#include<iostream>using namespace std;int main(){int max (int x =10, int y =20);max();cout << " max = " << max() << endl;return 0;}int max ( int x, int y){if (x>y) return x;else return y;}
第八题
#include<iostream>using namespace std;int sort(int &x,int &y){if(x<y) cout<<y<<","<<x<<endl;else cout <<x<<","<<y<<endl;}int main(){int a,b;cout<<"请输入两个整数"<<endl; cin>>a>>b; sort(a,b);return 0;}
第九题
#include<iostream>using namespace std;int paixu( int &a, int &b, int &c){ if( a < b) { if( b < c) { cout << "a < b < c" << endl; } else if ( a < c ) { cout << "a < c < b" << endl; } else { cout << "c < a < b" << endl; } } else if ( b > c ) { cout << " c < b < a " << endl; } else if ( a > c) { cout << " b < a < c " << endl; } else { cout << " b < c < a " << endl; }return 0;}int main(){int i , j ,k;cout << "a = ";cin >> i;cout << "b = ";cin >> j; cout << "c =" ;cin >> k;paixu (i, j, k);return 0;}
第十题
#include<iostream>
#include<string>using namespace std;int main(){ string str1,str2;cin>>str1;cin>>str2;str1=str1+str2;cout<<str1<<","<<str2<<endl; return 0;}
十一题
#include<iostream>#include<string>using namespace std;int main(){string a;cin>>a;int k=0;k=a.length();for(k=k-1;k>=0;k--){cout<<a[k];}return 0;}
十二题
#include<iostream>#include<string>using namespace std;void sort(string a ,string b ,string c, string d, string e){string ae[5]; string t;ae[0]=a; ae[1]=b; ae[2]=c; ae[3]=d; ae[4]=e;for (int i=0;i<4;i++){for(int j=i+1;j<5;j++){if(ae[j]<ae[i]){t=ae[j];ae[j]=ae[i];ae[i]=t;}}}for (int i=0;i<5;i++){cout<<ae[i]<<endl; }}int main(){string a,b,c,d,e; cin>>a>>b>>c>>d>>e;sort (a,b,c,d,e);return 0;}
十四题
#include<iostream>using namespace std;template <typename T>T paixu(T*a){int i, j, t;for(i = 0 ; i < 5 ; i++){for (j = 0 ; j < 5-i; j++ ){if( a[j] > a[j+1]){t = a[j];a[j] = a[j+1];a[j+1] = t; } }}return 0;}int main(){ int a[5] = {1,55,2,3,4};float b[5] = {1.1, 2.2,3.3,4.4,5.5}; double c[5] = {1.11,2.22,3.33,4.44,5.11};int i = 0;paixu(a);{for(i = 0 ; i < 5; i++){cout << a[i] << " ";}cout << endl;}paixu(b);{for(i = 0 ; i < 5; i++){cout << b[i] << " ";}cout << endl;}paixu(c);{for(i = 0 ; i < 5; i++){cout << c[i] << " ";}cout << endl;}return 0;}
0 0
- C++primer第一章习题
- c primer Plus第一章习题
- 《C Primer Plus》第一章 概览 课后习题
- C程序设计语言(第二版)习题:第一章
- C++primer[习题][第一章][1-10]
- C++primer[习题][第一章][11-20]
- C++primer[习题][第一章][21-25]
- c++primer 第一章课后习题 编程代码
- 第一章习题
- 第一章习题
- 第一章习题
- 第一章习题
- 第一章习题
- 第一章习题
- 第一章习题
- 第一章 习题
- 第一章习题
- C程序设计(第二版 新版)第一章 习题
- Ubuntu 13.10 安装后配置
- RedHat 6.3安装MySQL-server-5.6.13-1.el6.x86_64.rpm
- 从另一个qml文件中读取数据并显示在ListView中
- Android view的工作原理
- 这些情况与其闪辞,宁可不入职!
- 第一章C++习题
- 数据结构
- Android中 int 和 String 互相转换
- 第四周 项目四 指向学生类的指针
- 预览图片
- Linux系统开启IPv6任播(anycast)地址
- ios 为程序提供网络不好的环境测试(弱网)
- 每个程序员需掌握的20个代码命名小贴士
- 2015年乌鲁木齐德华医院爱鼻日公益活动火爆预约中