-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: YdrMaster <[email protected]>
- Loading branch information
Showing
7 changed files
with
105 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#include <iostream> | ||
|
||
int main(int argc, char **argv) { | ||
std::cout << "Hello world!" << std::endl; | ||
// TODO: 在控制台输出 "Hello, InfiniTensor!" 并换行 | ||
std::cout << "Hello, InfiniTensor!" << std::endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <iostream> | ||
|
||
int main(int argc, char **argv) { | ||
// TODO: 补全变量定义并打印加法运算 | ||
auto x = 1; | ||
std::cout << x << " + " << x << " = " << x + x << std::endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <iostream> | ||
|
||
// NOTE: 这是函数声明 | ||
int add(int, int); | ||
|
||
int main(int argc, char **argv) { | ||
auto x = 1, y = 2; | ||
std::cout << x << " + " << y << " = " << add(x, y) << std::endl; | ||
return 0; | ||
} | ||
|
||
// TODO: 补全函数定义 | ||
int add(int a, int b) { | ||
return a + b; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// See <https://stackoverflow.com/questions/156767/whats-the-difference-between-an-argument-and-a-parameter>. | ||
|
||
#include <iostream> | ||
|
||
void func(int param) { | ||
std::cout << "befor add: " << param << std::endl; | ||
param += 1; | ||
std::cout << "after add: " << param << std::endl; | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
auto arg = 99; | ||
std::cout << "befor func call: " << arg << std::endl; | ||
func(arg); | ||
std::cout << "after func call: " << arg << std::endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// See <https://stackoverflow.com/questions/156767/whats-the-difference-between-an-argument-and-a-parameter>. | ||
|
||
#include <iostream> | ||
|
||
void func(int param) { | ||
static int static_ = param; | ||
std::cout << "static_ = " << static_++ << std::endl; | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
func(5); | ||
func(4); | ||
func(3); | ||
func(2); | ||
func(1); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// See <https://stackoverflow.com/questions/156767/whats-the-difference-between-an-argument-and-a-parameter>. | ||
|
||
#include <iostream> | ||
|
||
constexpr int fibonacci(int i) { | ||
switch (i) { | ||
case 0: | ||
return 0; | ||
case 1: | ||
return 1; | ||
default: | ||
return fibonacci(i - 1) + fibonacci(i - 2); | ||
} | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
constexpr auto FIB25 = fibonacci(25); | ||
std::cout << "fibonacci(25) = " << FIB25 << std::endl; | ||
|
||
auto fib30 = fibonacci(30); | ||
std::cout << "fibonacci(30) = " << fib30 << std::endl; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,26 @@ | ||
add_rules("mode.debug", "mode.release") | ||
set_encodings("utf-8") | ||
|
||
target("00_hello_world") | ||
target("exercise00") | ||
set_kind("binary") | ||
add_files("exercises/00_hello_world/main.cpp") | ||
|
||
target("exercise01") | ||
set_kind("binary") | ||
add_files("exercises/01_variable&add/main.cpp") | ||
|
||
target("exercise02") | ||
set_kind("binary") | ||
add_files("exercises/02_function/main.cpp") | ||
|
||
target("exercise03") | ||
set_kind("binary") | ||
add_files("exercises/03_argument¶meter/main.cpp") | ||
|
||
target("exercise04") | ||
set_kind("binary") | ||
add_files("exercises/04_static/main.cpp") | ||
|
||
target("exercise05") | ||
set_kind("binary") | ||
add_files("exercises/05_constexpr/main.cpp") |