Created
March 21, 2024 02:58
-
-
Save MrEnder0/5ac652f42238579eeea0e0f6960f05db to your computer and use it in GitHub Desktop.
Square Triangle (I was bored in school)
This file contains hidden or 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
use std::num::NonZeroU64; | |
fn main() { | |
triangle(40); | |
cube(40); | |
} | |
fn cube(size: u64) { | |
match NonZeroU64::new(size) { | |
Some(_) => {}, | |
None => { | |
println!("Invalid size"); | |
return | |
} | |
}; | |
for _ in 0..size { | |
println!("{}", "*".repeat(size as usize)); | |
} | |
} | |
fn triangle(size: u64) { | |
match NonZeroU64::new(size) { | |
Some(_) => {}, | |
None => { | |
println!("Invalid size"); | |
return | |
} | |
}; | |
for row in 0..size { | |
println!("{}{}", " ".repeat(((size - row) /2) as usize), "*".repeat((row as usize) + 1)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment