Exercises
We'll cover the following...
Exercise 1
Last time, we implemented a factorial function using recursion. As a reminder, a factorial multiplies all the numbers from 1 to the target, so fact(5) == 1 * 2 * 3 * 4 * 5
. Write a fact
function using iteration and a while
loop instead of recursion.
Press + to interact
#[allow(unused_variables, unused_mut)]fn fact(x: i32) -> i32 {// Write your code here!0}
Exercise 2
Write a program that uses nested while
loops to produce this output:
X
XX
XXX
XXXX
XXXXX
XXXXXX
XXXXXXX
XX
...