File tree Expand file tree Collapse file tree 7 files changed +105
-2
lines changed Expand file tree Collapse file tree 7 files changed +105
-2
lines changed Original file line number Diff line number Diff line change 1
1
#include < iostream>
2
2
3
3
int main (int argc, char **argv) {
4
- std::cout << " Hello world!" << std::endl;
4
+ // TODO: 在控制台输出 "Hello, InfiniTensor!" 并换行
5
+ std::cout << " Hello, InfiniTensor!" << std::endl;
5
6
return 0 ;
6
7
}
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+
3
+ int main (int argc, char **argv) {
4
+ // TODO: 补全变量定义并打印加法运算
5
+ auto x = 1 ;
6
+ std::cout << x << " + " << x << " = " << x + x << std::endl;
7
+ return 0 ;
8
+ }
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+
3
+ // NOTE: 这是函数声明
4
+ int add (int , int );
5
+
6
+ int main (int argc, char **argv) {
7
+ auto x = 1 , y = 2 ;
8
+ std::cout << x << " + " << y << " = " << add (x, y) << std::endl;
9
+ return 0 ;
10
+ }
11
+
12
+ // TODO: 补全函数定义
13
+ int add (int a, int b) {
14
+ return a + b;
15
+ }
Original file line number Diff line number Diff line change
1
+ // See <https://stackoverflow.com/questions/156767/whats-the-difference-between-an-argument-and-a-parameter>.
2
+
3
+ #include < iostream>
4
+
5
+ void func (int param) {
6
+ std::cout << " befor add: " << param << std::endl;
7
+ param += 1 ;
8
+ std::cout << " after add: " << param << std::endl;
9
+ }
10
+
11
+ int main (int argc, char **argv) {
12
+ auto arg = 99 ;
13
+ std::cout << " befor func call: " << arg << std::endl;
14
+ func (arg);
15
+ std::cout << " after func call: " << arg << std::endl;
16
+ return 0 ;
17
+ }
Original file line number Diff line number Diff line change
1
+ // See <https://stackoverflow.com/questions/156767/whats-the-difference-between-an-argument-and-a-parameter>.
2
+
3
+ #include < iostream>
4
+
5
+ void func (int param) {
6
+ static int static_ = param;
7
+ std::cout << " static_ = " << static_++ << std::endl;
8
+ }
9
+
10
+ int main (int argc, char **argv) {
11
+ func (5 );
12
+ func (4 );
13
+ func (3 );
14
+ func (2 );
15
+ func (1 );
16
+ return 0 ;
17
+ }
Original file line number Diff line number Diff line change
1
+ // See <https://stackoverflow.com/questions/156767/whats-the-difference-between-an-argument-and-a-parameter>.
2
+
3
+ #include < iostream>
4
+
5
+ constexpr int fibonacci (int i) {
6
+ switch (i) {
7
+ case 0 :
8
+ return 0 ;
9
+ case 1 :
10
+ return 1 ;
11
+ default :
12
+ return fibonacci (i - 1 ) + fibonacci (i - 2 );
13
+ }
14
+ }
15
+
16
+ int main (int argc, char **argv) {
17
+ constexpr auto FIB25 = fibonacci (25 );
18
+ std::cout << " fibonacci(25) = " << FIB25 << std::endl;
19
+
20
+ auto fib30 = fibonacci (30 );
21
+ std::cout << " fibonacci(30) = " << fib30 << std::endl;
22
+
23
+ return 0 ;
24
+ }
Original file line number Diff line number Diff line change 1
1
add_rules (" mode.debug" , " mode.release" )
2
+ set_encodings (" utf-8" )
2
3
3
- target (" 00_hello_world " )
4
+ target (" exercise00 " )
4
5
set_kind (" binary" )
5
6
add_files (" exercises/00_hello_world/main.cpp" )
7
+
8
+ target (" exercise01" )
9
+ set_kind (" binary" )
10
+ add_files (" exercises/01_variable&add/main.cpp" )
11
+
12
+ target (" exercise02" )
13
+ set_kind (" binary" )
14
+ add_files (" exercises/02_function/main.cpp" )
15
+
16
+ target (" exercise03" )
17
+ set_kind (" binary" )
18
+ add_files (" exercises/03_argument¶meter/main.cpp" )
19
+
20
+ target (" exercise04" )
21
+ set_kind (" binary" )
22
+ add_files (" exercises/04_static/main.cpp" )
23
+
24
+ target (" exercise05" )
25
+ set_kind (" binary" )
26
+ add_files (" exercises/05_constexpr/main.cpp" )
You can’t perform that action at this time.
0 commit comments