To print a Rhombus Pattern in Rust, we use nested loops. The outer loop controls the number of rows, and the inner loops control the spaces and stars (*) to form the pattern.
In this example,
n
to represent the desired number of rows in the rhombus.for
loops, where the outer loop runs from 1 to n
and the inner loops control the spaces and stars in each row.fn main() {
let n = 5;
for i in 1..=n {
for _ in 0..(n - i) {
print!(" ");
}
for _ in 0..n {
print!("*");
}
println!();
}
}
***** ***** ***** ***** *****
In this tutorial, we learned How to print Rhombus Pattern in Rust language with well detailed examples.