Skip to content

Instantly share code, notes, and snippets.

@adityasuseno
Last active April 17, 2025 10:34
Show Gist options
  • Select an option

  • Save adityasuseno/ff77d51828ff3166d048ea2a8f28420a to your computer and use it in GitHub Desktop.

Select an option

Save adityasuseno/ff77d51828ff3166d048ea2a8f28420a to your computer and use it in GitHub Desktop.
Rust Program to Draw a Tree
use std::io;
fn main() {
loop {
println!("Enter number of rows : ");
let mut rows;
rows = String::new();
io::stdin().read_line(&mut rows).expect("Failed to read line");
let rows: u32 = match rows.trim().parse() {
Ok(num) => num,
Err(_) => {println!("Please enter natural number only! Try Again..."); continue},
};
for i in 0..rows {
for _j in 0..(rows - i - 1) {
print!(" ");
}
for _j in 0..(2 * i + 1) {
print!("*");
}
println!();
}
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment