Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
323 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
[package] | ||
name = "celToFah" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
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,18 @@ | ||
fn transFah(num: f64) -> f64 { | ||
(num * 1.8) + 32.0 | ||
} | ||
|
||
fn transCel(num: f64) -> f64 { | ||
(num - 32.0) / 1.8 | ||
} | ||
|
||
fn main() { | ||
let x = 32.0; | ||
|
||
println!("Fahrenheit is {}", transFah(x)); | ||
|
||
let y = 57.6; | ||
|
||
println!("Celsius is {}", transCel(y)); | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
[package] | ||
name = "fibonatch" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
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,5 @@ | ||
fn main() { | ||
let array_smp = [0,1,1,2,3,5,8,13,21,34,55,89,144,233,377]; | ||
|
||
println!("Fibonatch No.4 is {}", array_smp[3]) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
[package] | ||
name = "loops" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
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,49 @@ | ||
fn smpRev() { | ||
for number in (1..4).rev() { | ||
println!("{}!", number); | ||
} | ||
println!("LIFTOFF!!!"); | ||
} | ||
|
||
fn smpArray2() { | ||
let a = [10, 20, 30, 40, 50]; | ||
|
||
for element in a.iter() { | ||
println!("the value is: {}", element); | ||
} | ||
} | ||
|
||
fn smpArray() { | ||
let a = [10, 20, 30, 40, 50]; | ||
let mut index = 0; | ||
|
||
while index < 5 { | ||
println!("the value is: {}", a[index]); | ||
|
||
index = index + 1; | ||
} | ||
} | ||
|
||
fn smpLoop() { | ||
let mut number = 3; | ||
|
||
while number != 0 { | ||
println!("{}!", number); | ||
|
||
number = number + 1; | ||
} | ||
|
||
println!("LIFTOFF!!!"); | ||
} | ||
|
||
fn main() { | ||
/* | ||
loop { | ||
println!("again!"); | ||
} | ||
*/ | ||
// smpLoop(); | ||
smpArray(); | ||
smpArray2(); | ||
smpRev(); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
[package] | ||
name = "ownership" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
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,23 @@ | ||
fn smp_num() { | ||
let x = 5; | ||
let y = x; | ||
|
||
println!("x = {}, y = {}", x, y); | ||
} | ||
|
||
fn smp_copy() { | ||
let s1 = String::from("hello"); | ||
let s2 = s1.clone(); | ||
|
||
println!("s1 = {}, s2 = {}", s1, s2); | ||
} | ||
|
||
fn main() { | ||
let mut s = String::from("hello"); | ||
|
||
s.push_str(", world"); | ||
|
||
println!("{}", s); | ||
|
||
smp_copy(); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
[package] | ||
name = "variable" | ||
version = "0.1.0" | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] |
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,153 @@ | ||
fn smpLet() { | ||
let condition = true; | ||
let number = if condition { | ||
5 | ||
} else { | ||
6 | ||
}; | ||
|
||
println!("The value of number is: {}", number); | ||
} | ||
|
||
fn smpElseIf() { | ||
let number = 6; | ||
|
||
if number % 4 == 0 { | ||
println!("number is divisible by 4"); | ||
} else if number % 3 == 0 { | ||
println!("number is divisible by 3"); | ||
} else if number % 2 == 0 { | ||
println!("number is divisible by 2"); | ||
} else { | ||
println!("number is not divisible by 4, 3, or 2"); | ||
} | ||
} | ||
|
||
fn smpIf() { | ||
let number = 7; | ||
|
||
if number < 5 { | ||
println!("condition was true"); | ||
} else { | ||
println!("condition was false"); | ||
} | ||
} | ||
|
||
fn plus_one(x: i32) -> i32 { | ||
x + 2 | ||
} | ||
|
||
fn five() -> i32 { | ||
5 | ||
} | ||
|
||
fn smpScorp() { | ||
let x = 5; | ||
|
||
let y = { | ||
let x = 3; | ||
x + 1 | ||
}; | ||
|
||
println!("The value of y is: {}", y); | ||
} | ||
|
||
fn another_function(x: i32, y: i32) { | ||
println!("The value of x is: {}", x); | ||
println!("The value of y is: {}", y); | ||
} | ||
|
||
fn smpArray() { | ||
let a = [1, 2, 3, 4, 5]; | ||
|
||
let month = ["January", "February", "March", "April", "May", "June", "July", | ||
"August", "September", "October", "November", "December"]; | ||
|
||
let first = a[0]; | ||
let second = a[1]; | ||
} | ||
|
||
fn smpTup2() { | ||
let x: (i32, f64, u8) = (500, 6.4, 1); | ||
|
||
let five_hundred = x.0; | ||
|
||
let six_point_four = x.1; | ||
|
||
let one = x.2; | ||
|
||
println!("The value of x is: {}", five_hundred); | ||
println!("The value of y is: {}, {}", six_point_four, one); | ||
println!("The value of z is: {}", one); | ||
} | ||
|
||
fn smpTup() { | ||
let tup: (i32, f64, u8) = (500, 6.4, 1); | ||
|
||
let (x, y, z) = tup; | ||
|
||
println!("The value of y is: {}", y); | ||
} | ||
|
||
fn smpString() { | ||
let c = 'z'; | ||
let z = 'ℤ'; | ||
let heart_eyed_cat = '😻'; | ||
} | ||
|
||
fn smpBool() { | ||
let t = true; | ||
|
||
let f: bool = false; | ||
} | ||
|
||
fn smp_math() { | ||
let x = 2.0; | ||
|
||
let y: f32 = 3.0; | ||
|
||
let sum = 5 + 10; | ||
|
||
let difference = 95.5 - 4.3; | ||
|
||
let product = 4 * 30; | ||
|
||
let quotient = 56.7 / 32.2; | ||
|
||
let remainder = 43 % 5; | ||
} | ||
|
||
fn shadowing() { | ||
let x = 5; | ||
|
||
let x = x + 1; | ||
|
||
let x = x * 2; | ||
|
||
println!("The value of x is: {}", x); | ||
} | ||
|
||
fn main() { | ||
/* | ||
let mut x = 5; | ||
println!("The value of x is: {}", x); | ||
x = 6; | ||
println!("The value of x is: {}", x); | ||
*/ | ||
shadowing(); | ||
smpTup(); | ||
smpTup2(); | ||
another_function(5, 6); | ||
smpScorp(); | ||
|
||
let x = five(); | ||
|
||
println!("The value of x is: {}", x); | ||
|
||
let y = plus_one(5); | ||
|
||
println!("The value of x is: {}", y); | ||
smpIf(); | ||
smpElseIf(); | ||
smpLet(); | ||
} |