How to print text diagonally from left to right in Rust

1 Answer

0 votes
fn print_diagonal_text_ltr(text: &str) -> String {
    let mut output = String::new();

    for (i, ch) in text.chars().enumerate() {
        output.push_str(&" ".repeat(i));
        output.push(ch);
        output.push('\n');
    }

    output
}

fn main() {
    let result = print_diagonal_text_ltr("HELLO WORLD");
    
    print!("{}", result);
}


/*
run:

H
 E
  L
   L
    O
      
      W
       O
        R
         L
          D

*/

 



answered Apr 8 by avibootz
...