C++primer--Cp5
来源:互联网 发布:最简单的js幻灯片代码 编辑:程序博客网 时间:2024/06/06 09:34
5.2 factorial
int main(){ const int size = 16; array<long long, size>factorial; factorial[0] = factorial[1] = 1LL; for (int i = 2; i < size; i++ ) { factorial[i] = i*factorial[i - 1]; } for (int i = 0; i < size; i++) { cout << i << "! = " << factorial[i] << endl; } return 0;}
5.6 book selling
int main(){ string a[] = { "January "," February "," March "," April "," May "," June"," July "," August"," September "," October "," November "," December" }; double num[3][12]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 12; j++) { cout << "please input this " << i +1<<"\tyear's\t"<<a[j]<<"\tmonth's\t"<< "total num \t\n"; cin >> num[i][j]; } } int as[3] = {0}; for (int i = 0; i < 3; i++) { for (int j = 0; j < 12; j++) { as[i] += a[i][j]; } } return 0;}
5.7 car information
Attention! compile result is wrong
I suspect the “new ” part has some problems, for I’m unfamiliar with that;
struct car{ string proname; int proyear;};int main(){ int n = 0; cout << "how many cars do you have?\t\n"; cin >> n; car*p = new car[n]; cout << "rinima"; for (int i = 0; i < n; i++) { cout << "what's your car producer?\t\n"; cin >> p[n].proname; cout << "what's your car proyear?\t\n"; cin >> p[n].proyear; } for (int i = 0; i < n; i++) { cout << p[n].proname << "\t"; cout << p[n].proyear << endl; } return 0;}
5.8 total words
int main(){ string yime; int n=0; cout << "Enter words(to stop,type the word'done')\n"; while (yime != "done") { cin >> yime; n++ ; } cout << "you have total input " << n << "words"; return 0;}
阅读全文
0 0
- C++primer--Cp5
- CP5 多维数组
- C++primer
- 《C++primer》
- C++primer
- C++primer
- C++Primer
- 重读C++Primer-1
- C++Primer Dialy
- c++primer 13.7联合
- C++Primer 13.9类域
- c++primer学习小记
- C-PRIMER PLUS读书笔记
- C-PRIMER PLUS读书笔记
- C++Primer
- C++Primer学习小记
- c++primer问题思考
- 读c++primer
- spring的自动装配Bean与自动检测Bean
- web移动端viewport的理解
- Uva699
- 字典树-大量字符串前缀及出现次数是否存在统计(Trie树-java)算法实现
- CTF writeup:tomcat上传webshell后门
- C++primer--Cp5
- ubuntu 配置anaconda以及遇到的问题
- python 2017.7.1总结
- mysql配置主从
- Oracle分析函数KEEP、DENSE_RANK的使用
- CodeM美团点评编程大赛初赛B轮 B.送外卖2【三进制状压Dp】
- linux编译安装和yum安装
- HTML基础--基本概念 00
- 类内初始化与初始化列表与构造函数内部赋值