Solution Review 3: Print a Right-Angled Triangle
This lesson gives a detailed solution review to the challenge in the previous lesson.
We'll cover the following...
Solution
Press + to interact
fn test(n:i32) {// define a nested for loopfor i in 0..n { //outer loopfor j in 0..i + 1 { // inner loopprint!("&");}println!("");}}fn main(){println!("Right angled triangle when n = 5 ");test(5);println!("Right angled triangle when n = 6 ");test(6);}
Explanation
The value
n
is given to you for which the right-angled triangle needs to be printed.
nested for
loop
- On line 3, in the