Recursion

[Solved]
Report
-
Posts
2817
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
October 14, 2021
-
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 reply

Posts
2817
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
October 14, 2021
486
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