Last active
April 17, 2025 10:34
-
-
Save adityasuseno/ff77d51828ff3166d048ea2a8f28420a to your computer and use it in GitHub Desktop.
Rust Program to Draw a Tree
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::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