Recursion

Solved/Closed
katana - Jul 25, 2021 at 08:55 PM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Jul 26, 2021 at 12:02 PM
Hello,

Can you help me with my problem?

I was asked to make a program using recursion that allows user to input an integer and outputs a certain pattern.

Example:
Input: 5
Output:
IIIII
IIII
III
II
I

1 response

TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 552
Updated on Jul 26, 2021 at 12:03 PM
Hi Katana,

Not sure if this is what you are looking for, but I got this Excel VBA code for you:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A1")) Is Nothing Then Exit Sub

Dim mInt, x As Long

mInt = Range("A1").Value
Columns("B").ClearContents

For y = mInt To 1 Step -1
    Range("B" & x + 1).Value = Range("B" & x + 1).Value & "l"
    If y = 1 Then
        y = mInt - x
        x = x + 1
    End If
Next y
End Sub


After implementing the code (right-click sheets tab, view code, paste code in big white field) enter your integer in cell A1 and the result will be put in column B.

Best regards,
Trowa
0