File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1-
1+ include_directories ( ${ PROJECT_SOURCE_DIR } /primer/include )
22add_subdirectory (ch01 )
33add_subdirectory (ch02 )
44add_subdirectory (ch03 )
5- include_directories ( ${ PROJECT_SOURCE_DIR } /primer/include )
5+ add_subdirectory ( ch06 )
Original file line number Diff line number Diff line change 1+ add_executable (exercise6.3 exercise6.3.cpp )
2+ add_executable (exercise6.4 exercise6.4.cpp )
3+ add_executable (exercise6.5 exercise6.5.cpp )
4+ add_executable (exercise6.7 exercise6.7.cpp )
5+ add_executable (exercise6.8 exercise6.8.cpp )
6+ add_executable (exercise6.10 exercise6.10.cpp )
Original file line number Diff line number Diff line change 1+ //
2+ // Created by zing on 5/18/2020.
3+ //
4+ #include < iostream>
5+
6+ using namespace std ;
7+
8+ void swap (int *a, int *b) {
9+ int c = *a;
10+ *a = *b;
11+ *b = c;
12+ }
13+
14+ int main (int argc, char *argv[]) {
15+ int a = 10 ;
16+ int b = 11 ;
17+ cout << " a = " << a << " ,b = " << b << endl;
18+ swap (&a, &b);
19+ cout << " a = " << a << " ,b = " << b << endl;
20+ return 0 ;
21+ }
Original file line number Diff line number Diff line change 1+ //
2+ // Created by zing on 5/18/2020.
3+ //
4+
5+ #include < iostream>
6+ using namespace std ;
7+
8+ int fact (int val){
9+ int ret = 1 ;
10+ while (val > 1 ){
11+ ret *= val--;
12+ }
13+ return ret;
14+ }
15+
16+ int main (int argc, char *argv[]) {
17+ cout << fact (1 ) << endl;
18+ cout << fact (2 ) << endl;
19+ cout << fact (3 ) << endl;
20+ cout << fact (4 ) << endl;
21+ return 0 ;
22+ }
Original file line number Diff line number Diff line change 1+ //
2+ // Created by zing on 5/18/2020.
3+ //
4+
5+ #include < iostream>
6+
7+ using namespace std ;
8+
9+ int fact (int val) {
10+ int ret = 1 ;
11+ while (val > 1 ) {
12+ ret = ret * val;
13+ val--;
14+ }
15+ return ret;
16+ }
17+
18+ int main (int argc, char *argv[]) {
19+ int val = 0 ;
20+ cout << " please in put a number" << endl;
21+ cin >> val;
22+ cout << fact (val) << endl;
23+ return 0 ;
24+ }
Original file line number Diff line number Diff line change 1+ //
2+ // Created by zing on 5/18/2020.
3+ //
4+
5+ #include < iostream>
6+
7+ using namespace std ;
8+
9+ int abs (int val){
10+ if (val < 0 )
11+ return -1 *val;
12+ return val;
13+ }
14+
15+ int main (int argc, char *argv[]) {
16+ cout << abs (1 ) << endl;
17+ cout << abs (0 ) << endl;
18+ cout << abs (-1 ) << endl;
19+ return 0 ;
20+ }
Original file line number Diff line number Diff line change 1+ //
2+ // Created by zing on 5/18/2020.
3+ //
4+
5+ #include < iostream>
6+
7+ using namespace std ;
8+
9+ int increasing () {
10+ static int val = 0 ;
11+ return val++;
12+ }
13+
14+ int main (int argc, char *argv[]) {
15+
16+ cout << increasing () << endl;
17+ cout << increasing () << endl;
18+ cout << increasing () << endl;
19+ cout << increasing () << endl;
20+ cout << increasing () << endl;
21+ return 0 ;
22+ }
Original file line number Diff line number Diff line change 1+ //
2+ // Created by zing on 5/18/2020.
3+ //
4+
5+ #include < iostream>
6+ #include " exercise6.8.h"
7+ using namespace std ;
8+ int main (int argc, char *argv[]) {
9+ print ();
10+ print ();
11+ cout << fact (5 ) << endl;
12+ cout << fact (6 ) << endl;
13+ return 0 ;
14+ }
Original file line number Diff line number Diff line change 1+ //
2+ // Created by zing on 5/18/2020.
3+ //
4+
5+ #ifndef LEARN_CPP_EXERCISE6_8_H
6+ #define LEARN_CPP_EXERCISE6_8_H
7+
8+ #include < iostream>
9+ using namespace std ;
10+ void print (){
11+ cout << " hello world" << endl;
12+ }
13+ int fact (int val){
14+ int ret = 1 ;
15+ while (val > 1 ){
16+ ret *= val--;
17+ }
18+ return ret;
19+ }
20+
21+ #endif // LEARN_CPP_EXERCISE6_8_H
You can’t perform that action at this time.
0 commit comments